Show data from table even if there is no data!! Oracle

后端 未结 3 1734
悲&欢浪女
悲&欢浪女 2021-01-25 05:34

I have a query which shows count of messages received based on dates. For Eg:

1 | 1-May-2012 
3 | 3-May-2012 
4 | 6-May-2012 
7 | 7-May-2012 
9 | 9-May-2012 
5 |         


        
3条回答
  •  深忆病人
    2021-01-25 05:51

    You don't need a separate table for this, you can create what you need in the query. This works for May:

    WITH month_may AS (
        select to_date('2012-05-01', 'yyyy-mm-dd') + level - 1 AS the_date
        from dual
        connect by level < 31
    )
    SELECT *
      FROM month_may mm
      LEFT JOIN mytable t ON t.some_date = mm.the_date
    

    The date range will depend on how exactly you want to do this and what your range is.

提交回复
热议问题