我有一个保存工作的工作表,而Leaddate是工作条目的字段。
我想要得到的结果是我每个季度的工作数量。我的查询统计了Leaddate字段中每个日期的作业。
这是查询
select count(jobid) as jobcount, leaddate
from jobs
where contactid='19249'
group by leaddate
最佳答案
我认为这应该可以做到:
SELECT YEAR(leaddate) AS year, QUARTER(leaddate) AS quarter, COUNT(jobid) AS jobcount
FROM jobs
WHERE contactid = '19249'
GROUP BY YEAR(leaddate), QUARTER(leaddate)
ORDER BY YEAR(leaddate), QUARTER(leaddate)