简体   繁体   中英

Extract Data as per Date Logic in Oracle SQL

I need to extract the data from Oracle DB and this is the business requirement:

  1. On Sunday and Monday, need to extract data as of previous Thursday
  2. From Tuesday to Saturday, need to extract data as of (Date column -2)

Need assistance on where clause logic.

This is not an answer.

  1. Is Monday, Tuesday as the day when query is run or something else?
  2. On Tuesday the query should extract all those records where the date column matches two days before today? Can you provide sample data and expected result?

That would be

select *
from your_table
where date_column = 
  case when to_char(sysdate, 'dy') in ('sun', 'mon') then next_day(trunc(sysdate) - 7, 'thu')
       else trunc(sysdate) - 2
  end;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM