3
$SQLString = "SELECT    
            count(score) as counts,
            DATE(date),
            SUM(CASE WHEN gender = 1 then 1 ELSE 0 END) Male,
            SUM(CASE WHEN gender = 2 then 1 ELSE 0 END) Female,
            AVG(age) as age, score
            FROM persons  
            WHERE date > '".$_SESSION['date1']."' AND date < '".$_SESSION['date2']."' 
            GROUP BY DATE(date) 
            ORDER BY DATE(date) asc";   

这是我的查询,每天显示一些数据,如性别、年龄等。如何按月或年汇总这些日期并显示添加的数据?

如果我也没有解释我的自我,请注意我:)

4

1 回答 1

5

GROUP BY year(date), month(date).

于 2012-11-20T17:24:37.193 回答