ORACLE 使用语句查询三天前数据(不包括星期六星期天 )    查询三天的数据中如果包括周末,则对应的加一天或两天。
列子1:今天星期1  那么我需要查询到的数据就是  上周 星期六、星期日、星期五、星期四、星期三的数据   ;
列子2: 如果今天星期5  查询到数据  星期四、星期三、星期二的数据 ;
此处查询非单条查询 

解决方案 »

  1.   

    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)
      

  2.   

    思路就是 用to_char(sysdate,'d')取出当前是 这周的第几天,周末为第一天,开始
      

  3.   

    把今天 是周几,decode 一下,再枚举往回倒腾几天。
      

  4.   


    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)