ORACLE 使用陳述句查詢三天前資料(不包括星期六星期天 ) 查詢三天的資料中如果包括周末,則對應的加一天或兩天。
列子1:今天星期1 那么我需要查詢到的資料就是 上周 星期六、星期日、星期五、星期四、星期三的資料 ;
列子2: 如果今天星期5 查詢到資料 星期四、星期三、星期二的資料 ;
此處查詢非單條查詢
uj5u.com熱心網友回復:
select* from t1 where trunc(rq) >(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)
uj5u.com熱心網友回復:
思路就是 用to_char(sysdate,'d')取出當前是 這周的第幾天,周末為第一天,開始uj5u.com熱心網友回復:
把今天 是周幾,decode 一下,再列舉往回倒騰幾天。uj5u.com熱心網友回復:
這個 陳述句 缺乏運算式uj5u.com熱心網友回復:
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)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/68270.html
標籤:基礎和管理
上一篇:請問下,ibatis判斷的寫法
