SQL Count for each date

后端 未结 7 674
盖世英雄少女心
盖世英雄少女心 2021-02-03 21:57

I have the following need

I have a logging table which logs som leads generated each day.

Now I need to pull a report over the amount of leads for each day over

7条回答
  •  盖世英雄少女心
    2021-02-03 22:25

    It is most efficient to do your aggregation by integer and then convert back to datetime for presentation.

    select 
        cast(daybucket - 1 as datetime) as count_date,
        counted_leads
    from 
        (select 
             cast(created_date as int) as DayBucket,
             count(*) as counted_leads
         from mytable
         group by cast(created_date as int) ) as countByDay
    

提交回复
热议问题