如何在PHP中找到按月过滤的总金额?

时间:2011-12-21 07:47:02

标签: php mysql date

我试图查找REPORT_STATUS IN REPORT表的总金额,但我不知道如何。我只能计算REPORT_STATUS而不是按月计算。

$count = "SELECT 
(SELECT COUNT(REPORT_STATUS) FROM REPORT WHERE REPORT_STATUS = 1 ) as 
NumberOfReport1, (SELECT COUNT(REPORT_STATUS)  FROM REPORT WHERE REPORT_STATUS = 2) 
as NumberOfAReport2,(SELECT COUNT(REPORT_STATUS)  FROM REPORT WHERE REPORT_STATUS = 3) 
as NumberOfReport3,(SELECT COUNT(REPORT_STATUS)  FROM REPORT WHERE REPORT_STATUS = 4) 
as NumberOfReport4 ";

$result1= mysql_query($count);

1 个答案:

答案 0 :(得分:0)

GROUP BY是你的朋友。像这样:

SELECT month, COUNT(REPORT_STATUS) FROM REPORT WHERE REPORT_STATUS = 1 GROUP BY month