How do I group a date field to get quarterly results in MySQL?

前端 未结 4 1589
孤独总比滥情好
孤独总比滥情好 2020-12-18 19:47

I have a job table that holds jobs and leaddate is the field for the job entry.

The result I want to get is the number of jobs I have in each quarter. My query count

4条回答
  •  不知归路
    2020-12-18 20:20

    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)
    

提交回复
热议问题