0

需要有关 oracle sql 的帮助,以获取从昨天的 1500 小时到今天的 2400 小时的“已删除”数据的子集。

超集将从昨天的 1500 小时到今天的 1500 小时“过境”

我的查询只是从昨天的 1500 小时到今天的 1500 小时“下降”

with A99 as
 (   
  SELECT shipment_id, 
         holder_employee_id
  FROM (
        SELECT distinct shipment_id, 
               holder_employee_id, 
               shipment_status_id,
               row_number() 
                 OVER (
                      PARTITION BY shipment_id ORDER BY CHANGE_DATE DESC
                      ) AS rn1
        FROM db.table1
        where (
                (TRUNC(CHANGE_DATE) = to_date('{RUN_DATE_YYYY-MM-DD}', 'YYYY-MM-DD')-1 AND TO_CHAR(CHANGE_DATE,'HH24') >=15)
                or 
                (TRUNC(CHANGE_DATE) = to_date('{RUN_DATE_YYYY-MM-DD}', 'YYYY-MM-DD') 
                    AND TO_CHAR(CHANGE_DATE,'HH24') <=15)
               )
        and region_id=4
        ) 
  WHERE rn1 = 1 AND shipment_status_id in ('intransit')
 )
select distinct cs.tracking_id,
                ce.store_id,
                ce.store_name,
                cst.station_code, 
                case 
                    when cssh.shipment_status_id in ('dropped')  
                         and TRUNC(cssh.CHANGE_DATE) >= to_date('{RUN_DATE_YYYY-MM-DD}', 'YYYY-MM-DD')-1 
                      then 0 
                    else 1 
                end as DAS_STATUS
from A99
inner join db.table1 cssh 
  on cssh.shipment_id=A99.shipment_id
inner join db.table2 cs 
  on cs.shipment_id=A99.shipment_id
inner join db.table3 ce 
  on ce.employee_id = A99 .holder_employee_id 
inner join db.table4 cst 
  on cst.station_id= ce.station_id 
where TRUNC(cssh.CHANGE_DATE) >= to_date('{RUN_DATE_YYYY-MM-DD}', 'YYYY-MM-DD')-1 
4

0 回答 0