$sq ="
SELECT count(noofrows),QUARTER(Date(last_call)) as quarter,YEAR(last_call)
FROM $dbt.travel_crm
WHERE Date(last_call) BETWEEN '".$_GET['startdate']."'
AND '".$_GET['enddate']."'
GROUP BY QUARTER(Date(last_call))
ORDER BY YEAR(last_call)";

由于按季度分组,所以只考虑当前年份行数,所以我需要按(quarter,year)分组,我如何才能做到这一点?

最佳答案

如果您需要按季度和年度分组,请执行以下操作:

GROUP BY YEAR(last_call), QUARTER(last_call)

关于mysql - MySQL按季度编号获取季度的开始和结束日期,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6070697/

10-15 07:48