本文介绍了如何分组一个日期字段来获取MySQL的季度结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一份工作表,可以保留工作,而铅笔是工作条目的领域。
I have a job table that holds jobs and leaddate is the field for the job entry.
我想得到的结果是我拥有的工作数量每个季度我的查询计算了leaddate字段中每个日期的作业。
The result I want to get is the number of jobs I have in each quarter. My query counts jobs of each date in the leaddate field.
这是查询
select count(jobid) as jobcount, leaddate
from jobs
where contactid='19249'
group by leaddate
推荐答案
我认为这应该做这个工作:
I think this should do the job:
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)
这篇关于如何分组一个日期字段来获取MySQL的季度结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!