仅在一天内变化

时间:2018-03-29 10:19:53

标签: google-bigquery

date_add(a.Order_date,4,"Hour") > "2018-03-27 15:00:00"

是在我每天运行的查询中提取数据的标准。所以基本上,我希望每天只有一天改变但是休息一样。 有人可以帮忙吗?

SELECT 
a.order as Order_Number,unique(b.status_name) as Status, 
date_add(a.Order_date,4,"Hour") as Ordered_Date, 
date_add(a.Export_date,4,"Hour") as Exported_Date, 
date_add(a.Dispatch_date,4,"Hour") as Dispatched_Date 
FROM 
[ops_views.Order_Timeline] as a 
left join [ops_views.sales_order_item] as b 
ON a.Order=b.order_nr 
WHERE 
LEFT(a.Order,2)="AE" AND 
date_add(a.Order_date,4,"Hour") > "2018-03-26 15:00:00" AND 
date_add(a.Order_date,4,"Hour") <= "2018-03-27 15:00:00" and 
b.status_name not in ("test_invalid","invalid","canceled","canceled_exportable") 
GROUP BY 1,3,4,5,

1 个答案:

答案 0 :(得分:2)

所以,如果(例如)你需要在昨天下午3点到前天下午3点之间的时间段内过滤数据 - 你可以使用类似下面的内容(BigQuery Standard SQL)

   
AND DATE_ADD(a.Order_date,4,"Hour") > 
    FORMAT_DATE('%Y-%m-%d 15:00:00', DATE_SUB(CURRENT_DATE(), INTERVAL 2 DAY)) 
AND DATE_ADD(a.Order_date,4,"Hour") <= 
    FORMAT_DATE('%Y-%m-%d 15:00:00', DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY))