ITeye博客

oracle 查询一条记录中两个时间的所有日期

lxcaoxin · 2013-03-19 12:51 · Oracle · 数据库 · Markdown

test表结构和数据如下: id rate start_date end_date 1 0.8 2013-02-01 2013-02-15 2 0.6 2013-02-16 2013-02-28 3 0.4 2013-03-01 2013-03-10

查出每条记录的start_date 和end_date之间的所有日期和对应的rate 结果: id rate date 1 0.8 2013-02-01 1 0.8 2013-02-02 1 0.8 2013-02-03 ...... 3 0.4 2013-03-10

SQL:


select a.id,rate, a.start_date, a.end_date, a.start_date+b.dis-1 h from
test a,
(select rownum dis from 
    (select max(end_date-start_date)+1 gap from test)
connect by rownum<=gap) b
where a.end_date>=a.start_date+b.dis-1
order h


评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。