ORACLE 使用语句查询三天前数据(不包括星期六星期天 ) 查询三天的数据中如果包括周末,则对应的加一天或两天。
列子1:今天星期1 那么我需要查询到的数据就是 上周 星期六、星期日、星期五、星期四、星期三的数据 ;
列子2: 如果今天星期5 查询到数据 星期四、星期三、星期二的数据 ;
此处查询非单条查询
列子1:今天星期1 那么我需要查询到的数据就是 上周 星期六、星期日、星期五、星期四、星期三的数据 ;
列子2: 如果今天星期5 查询到数据 星期四、星期三、星期二的数据 ;
此处查询非单条查询
(select case to_char(sysdate,'d')
when in (2,3,4) then trunc(sysdate)+5
when in (5,6,7) then trunc(sysdate)+3
when in (1) then trunc(sysdate)+4
end from dual)
select* from t1 where trunc(rq) >
(select case when to_char(sysdate,'d') in (2,3,4) then trunc(sysdate)+5
case when to_char(sysdate,'d') in (5,6,7) then trunc(sysdate)+3
else trunc(sysdate)+4
end from dual)