从日期范围生成日期行

时间:2014-09-23 10:51:48

标签: sql postgresql between date-range

我想运行像

这样的查询
select ... as days where `date` is between '2010-01-28' and '2010-02-03'

并返回如下数据:

days
---
28
29
30
31
1
2
3

1 个答案:

答案 0 :(得分:2)

select extract(day from d) as days
from generate_series(timestamp '2010-01-28', timestamp '2010-02-03', interval '1' day) as d
order by d;

SQLFiddle示例:http://sqlfiddle.com/#!15/d41d8/3464