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

前端 未结 4 1582
孤独总比滥情好
孤独总比滥情好 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:11

    you can use the Quarter function to get a quarter from date:

    select count(jobid) as jobcount, QUARTER(leaddate) as qt, YEAR(leaddate) as year
    from jobs
    where contactid='19249'
    group by year,qt
    

提交回复
热议问题