SQL query for Figuring counts by month

后端 未结 2 806
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-13 04:18

whats a good way to join 1-12 in a column to a bunch of counts by month?... in SQL

SELECT
    months???,
    count(whatever1) count1,
    count(whatever2) co         


        
2条回答
  •  悲哀的现实
    2021-01-13 05:20

    basically where is a slick way to get my months list/table/whatever

    You can use a recursive cte to build a list of months.

    ;with Months(MonthNum) as
    (
      select 1 MonthNum
      union all
      select MonthNum+1
      from Months
      where MonthNum < 12 
    )
    
    -- Your query goes here
    select * 
    from Months
    

提交回复
热议问题