[英]How to aggregate dates by months or years Mysql
$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";
This is my Query that display some data, like gender,age, etc per day. 这是我的查询,显示一些数据,如性别,年龄等每天。 How could I aggregate those dates by months or years and display the added data?
我怎样才能将这些日期按月或年汇总并显示添加的数据?
Notice me if Im not explain my self as well :) 如果我不解释我自己,请注意我:)
GROUP BY year(date), month(date)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.