Sybase - 仅返回过去三天的数据

问题描述

我对此很陌生。我有一个声明,我只想根据shipment_datedelivered 返回最近三天的数据。我可以使用哪些日期函数来实现这一点?我正在使用 Sybase。

 select dba.disp_ship.ds_id,dba.disp_ship.ds_origin_id,dba.disp_ship.ds_findest_id,dba.disp_ship.ds_billto_id,dba.disp_ship.ds_bill_charge,dba.disp_ship.ds_ref1_text,dba.disp_ship.ds_status,dba.disp_ship.ds_bill_date,dba.disp_ship.ds_ship_date,dba.disp_ship.ds_ship_type,dba.disp_ship.movecode,dba.companies.co_id,dba.companies.co_name,dba.current_shipments.cs_id,dba.current_shipments.cs_event_count,dba.current_shipments.cs_routed,dba.current_shipments.cs_assigned,dba.current_shipments.cs_completed,dba.current_shipments.shipment_datedelivered,(CASE ds_status WHEN 'A' THEN 'TEMPLATE'
WHEN 'C' THEN 'CANCELLED'
WHEN 'D' THEN 'DECLINED'
WHEN 'E' THEN 'QUOTED'
WHEN 'F' THEN 'OFFERED' 
WHEN 'H' THEN 'PENDING'
WHEN 'K' THEN 'OPEN'
WHEN 'N' THEN 'AUTHORIZED'
WHEN 'Q' THEN 'AUDIT required'
WHEN 'T' THEN 'AUDITED'
WHEN 'W' THEN 'BILLED' 
END) AS 'BILLING STATUS',(CASE ds_ship_type WHEN '2201' THEN 'MONTREAL'
WHEN '2202' THEN 'DRYVAN'
WHEN '2203' THEN 'broKERAGE'
WHEN '2204' THEN 'OLD broKERAGE (NO GOOD)'
WHEN '2205' THEN 'LIFTING'
WHEN '2206' THEN 'WAREHOUSE'
END) AS 'DIVISION',(CASE WHEN dba.current_shipments.cs_event_count = dba.current_shipments.cs_completed
THEN 'OPEN COMPLETED' 
ELSE 'INCOMPLETE'
END) 
 AS 'STATUS' 
from dba.disp_ship
inner join dba.companies ON dba.disp_ship.ds_billto_id=dba.companies.co_id
inner join dba.current_shipments ON dba.disp_ship.ds_id=DBA.current_shipments.cs_id  

解决方法

好吧,我想我刚刚明白了。我将此添加到查询的末尾,现在我正在获取所需的数据。

where shipping_datedelivered >= dateadd(day,-3,GETDATE())