日期:2014-05-16 浏览次数:20825 次
WITH t AS
(SELECT 1023 mt,DATE '2013-12-9' dat,'n' flag FROM dual
UNION ALL
SELECT 1998 mt,DATE '2013-12-8' dat,'n' flag FROM dual
UNION ALL
SELECT 1999 mt,DATE '2013-12-7' dat,'y' flag FROM dual
UNION ALL
SELECT 2525 mt,DATE '2013-12-6' dat,'n' flag FROM dual
UNION ALL
SELECT 1999 mt,DATE '2013-12-4' dat,'y' flag FROM dual
UNION ALL
SELECT 2397 mt,DATE '2013-12-5' dat,'n' flag FROM dual
),
a AS (SELECT mt,dat,flag,ROWNUM rn FROM t WHERE t.dat <=DATE'2013-12-9' AND t.flag = 'y' ORDER BY dat DESC)
SELECT SUM(T.MT)
FROM T, A
WHERE T.DAT <= DATE '2013-12-9'
AND T.DAT > A.DAT
AND A.RN = 1
ORDER BY T.DAT DESC;
with test as
(select 1023 amt, to_date('2013-12-09', 'yyyy-mm-dd') dt, 'N' Lable
from dual
union all
select 1998 amt, to_date('2013-12-08', 'yyyy-mm-dd') dt, 'N' Lable
from dual
union all
select 1999 amt, to_date('2013-12-07', 'yyyy-mm-dd') dt, 'Y' Lable
from dual
union all
select 2525 amt, to_date('2013-12-06', 'yyyy-mm-dd') dt, 'N' Lable
from dual
union all
select 2397 amt, to_date('2013-12-05', 'yyyy-mm-dd') dt, 'Y' Lable
from dual
u