Oracle: select missing dates

后端 未结 4 752
耶瑟儿~
耶瑟儿~ 2021-01-03 05:09

I have a table with (among other things) dates in a field.

I need to get a list of all dates that are more recent than the oldest date, older than the most recent

4条回答
  •  独厮守ぢ
    2021-01-03 05:33

    You need a Calendar table (either permanent or created on the fly). Then you could do a simple:

    SELECT c.my_date
    FROM 
            calendar c
        JOIN
            ( SELECT MIN(date_column) AS min_date 
                   , MAX(date_column) AS max_date 
              FROM tableX
            ) mm
          ON c.mydate BETWEEN min_date AND max_date
    WHERE
        c.my_date NOT IN
        ( SELECT date_column
          FROM tableX
        )
    

提交回复
热议问题