简体   繁体   English

根据 Oracle SQL 中的日期逻辑提取数据

[英]Extract Data as per Date Logic in Oracle SQL

I need to extract the data from Oracle DB and this is the business requirement:我需要从 Oracle 数据库中提取数据,这是业务需求:

  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)从周二到周六,需要提取截至(日期列-2)的数据

Need assistance on where clause logic.需要关于 where 子句逻辑的帮助。

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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