增加时间段过滤,该如何修改这个SQL语句?
select t1.SORDER,一课周期,塑封周期,二课周期,三课周期
from
(select A.SORDER,to_char((max(A.jstetm)-min(A.jststm))*24,'990.99')||'小时' AS
一课周期
from factv2.SAGPLNFL A,FACTV2.SGPROGSS B
Where B.WAREHUSFG=1 AND
A.SORDER=B.SORDER and
A.KOTECD>=2015 and A.KOTECD<=2026
group by A.sorder
) t1 ,
(select A.SORDER,to_char((max(A.jststm)-min(A.jstetm))*24,'990.99')||'小时' AS
塑封周期
from factv2.SAGPLNFL A,FACTV2.SGPROGSS B
Where B.WAREHUSFG=1 AND
A.SORDER=B.SORDER and
A.KOTECD>=2026 and A.KOTECD<=2036
group by A.sorder
) t2,
(select A.SORDER,to_char((max(A.jstetm)-min(A.jststm))*24,'990.99')||'小时' AS
二课周期
from factv2.SAGPLNFL A,FACTV2.SGPROGSS B
Where B.WAREHUSFG=1 AND
A.SORDER=B.SORDER and
A.KOTECD>=2036 and A.KOTECD<=2075
group by A.sorder
) t3,
(select A.SORDER,to_char((max(B.WAREHUSFG_DATE)-min(A.jststm))*24,'990.99')||'
小时' AS 三课周期
from factv2.SAGPLNFL A,FACTV2.SGPROGSS B
Where B.WAREHUSFG=1 AND
A.SORDER=B.SORDER and
A.KOTECD>=2075
group by A.sorder
) t4
where t1.SORDER=t2.SORDER
and t1.SORDER=t3.SORDER
and t1.SORDER=t4.SORDER
ORDER BY t1.SORDER
现在在这个结果集(ADORS)中增加一个时间段条件:
即根据t4中的WAREHUSFG_DATE(日期字段)在某一个时间范围内过滤整个结果集(ADORS)。
比如时间段为2010-2-26到2010-3-25,那么过滤后的结果集只显示符合过滤条件的记录。
请问大大们,该如何修改这个SQL语句?
数据库为ORACLE
先谢谢了。
------解决方案--------------------
直接在T4里就过滤掉,和你的需求满足?你试试
(select A.SORDER,to_char((max(B.WAREHUSFG_DATE)-min(A.jststm))*24,'990.99')||'
小时' AS 三课周期
from factv2.SAGPLNFL A,FACTV2.SGPROGSS B
Where B.WAREHUSFG=1 AND
A.SORDER=B.SORDER and
A.KOTECD>=2075
AND B.WAREHUSFG_DATE BETWEEN TO_DATE('2010-2-25','YYYY-MM-DD') AND TO_DATE('2010-3-26','YYYY-MM-DD')
group by A.sorder
) t4
------解决方案--------------------
那你在T1,T2,T3里分别加时间段就可以了?是这样的需求?