How can I get a table of dates from the first day of the month, two months ago, to yesterday?

后端 未结 3 1200
情歌与酒
情歌与酒 2021-01-20 06:26

I have a situation that I would normally solve by creating a feeder table (for example, every date between five years ago and a hundred years into the future) for querying b

3条回答
  •  时光说笑
    2021-01-20 06:52

    I haven't used DB2 before but in SQL Server you could do something like the following. Note that you need a table with at least the number of rows as you need days.

    SELECT TOP 45 
        DATEADD(d, ROW_NUMBER() OVER(ORDER BY [Field]) * -1, GETDATE())
    FROM 
        [Table]
    

提交回复
热议问题