0

次のような MYSQL データベースのクエリがあります。

SELECT name,
SUM(IF(date_format (date, '%b, %Y')= 'Dec, 2011', 1,0)) AS `month1`, 
SUM(IF(date_format (date, '%b, %Y')= 'Jan, 2012', 1,0)) AS `month2`, 
SUM(IF(date_format (date, '%b, %Y')= 'Feb, 2012', 1,0)) AS `month3`, 
etc...
COUNT(*) AS total FROM table order by total

ただし、合計ではなく、月 1 から月 12 までの平均が必要です。

編集-SUMMED数値(月1、2など)を保持する必要がありますが、それらすべての平均を計算する必要もあります。

したがって、月 1 ~ 12 の結果が -

55、60、70、54、89、58、68、78、65、89、73、81、合計は 840

これらすべての数値の平均を計算する必要があります (70)

ありがとう

4

2 に答える 2

0
SELECT name,
AVG(IF(date_format (date, '%b, %Y')= 'Dec, 2011', 1,0)) AS `month1`, 
AVG(IF(date_format (date, '%b, %Y')= 'Jan, 2012', 1,0)) AS `month2`, 
AVG(IF(date_format (date, '%b, %Y')= 'Feb, 2012', 1,0)) AS `month3`, 
-- etc...
COUNT(*) AS total FROM table order by total
于 2013-01-16T14:16:01.573 に答える
0

単純:

SELECT name,
AVG(IF(date_format (date, '%b, %Y')= 'Dec, 2011', 1,0)) AS `month1`, 
AVG(IF(date_format (date, '%b, %Y')= 'Jan, 2012', 1,0)) AS `month2`, 
AVG(IF(date_format (date, '%b, %Y')= 'Feb, 2012', 1,0)) AS `month3`, 
etc...
COUNT(*) AS total FROM table order by total
于 2013-01-16T14:16:02.343 に答える