SQL Date Query include month even if no data

前端 未结 2 1054
旧巷少年郎
旧巷少年郎 2021-01-28 04:38

I have a booking database with various dates for each booking. I want to get a count of all bookings in each month e.g.

JAN | 12
FEB | 15
MAR | 53
APR | 25
         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-28 04:58

    The easy way is using a months table because you can have empty months.

    create table months (
       month_id integer,
       date_ini datetime,
       date_end datetime
    ) 
    

    And this are some examples of how create that table automatic

    Using select Generate days from date range

    This use store procedure in MSQL

提交回复
热议问题