求一跟运行规律有关的sql语句
假如有趟车有开行规律,10代表隔日开,110代表开两天停一天,依此类推,
有一个表:
act_date start_date stop_date rule checi
2007-0817 2007-0817 2007-0825 10 111
能不能根据开行规律得到下面结果:
act_date checi
2007-0817 111
2007-0819 111
2007-0821 111
2007-0823 111
2007-0825 111
谢谢!
------解决方案--------------------8月17的帖子,也不知道楼主还在不在,呵呵。
SELECT bb
FROM (SELECT tt.start_date + ROWNUM - 1 bb,
SUBSTR (RPAD (tt.rule,
(tt.stop_date - tt.start_date + 1),
tt.rule
),
ROWNUM,
1
) cc
FROM all_objects,
(SELECT TO_DATE ( '2007-08-17 ', 'yyyy-mm-dd ') AS act_date,
TO_DATE ( '2007-08-17 ', 'yyyy-mm-dd ') AS start_date,
TO_DATE ( '2007-08-25 ', 'yyyy-mm-dd ') AS stop_date,
10 AS rule, 111 checi
FROM DUAL) tt
WHERE ROWNUM <= tt.stop_date - tt.start_date + 1)
WHERE cc = 1