oracle 表a,有3列,id,start(date),end(date)

问题描述:

oracle 表a,有3列,id,start(date),end(date)
有两条数据:
1 2011-04-10 2011-04-11
2 2011-04-12 2011-04-13
我想显示:
1 2011-04-10
1 2011-04-11
2 2011-04-12
2 2011-04-13
开始时间和结束时间是间隔的
1 2011-04-10 2011-04-12
2 2011-04-13 2011-04-15
显示:
1 2011-04-10
1 2011-04-11
1 2011-04-12
2 2011-04-14
2 2011-04-13
2 2011-04-15
1个回答 分类:综合 2014-09-18

问题解答:

我来补答
select * from
(select a.id,a.start as tdate
union all
select a.id,a.end as tdate) t
order by t.id,t.tdate
再问: 开始时间和结束时间是间隔的 1 2011-04-10 2011-04-12 2 2011-04-13 2011-04-15 显示: 1 2011-04-10 1 2011-04-11 1 2011-04-12 2 2011-04-14 2 2011-04-13 2 2011-04-15
再答: 这个就比较麻烦了,如果单是这两条数据,或许还有办法,只是速度会慢点,如果是不止这两条数据,是未知的id个数,恐怕就困难了,因为构建连续日期,这个算法太麻烦了。 select id,trunc(start) + rownum -1 as tdate from all_objects(这个表可以用一个数据量大点的表代替,只要行数大于需要显示的足够多的天数就可以), a where rownum
 
 
展开全文阅读
剩余:2000
上一页:课时练P3
也许感兴趣的知识