您好,我正在尝试针对昨天运送的In TAT或Out TAT的客户计算产品数量的总和。
这是示例数据
client_name order_id created_at ship_at quantity
XYZ 232 1,558,439,472,664,000 1,987,456,957,999,000 45
KHD 2234 1,558,254,233,234,000 1,987,456,957,999,000 34
DSS 2574 1,678,678,467,234,000 1,987,456,957,999,000 2
SDD 9874 1,578,132,345,547,000 1,987,456,957,999,000 23
在此查询中,我可以计算昨天针对客户运送的产品数量总和
SELECT "client_name" AS "Client Name",
"fc" AS "Warehouse",
SUM("quantity") AS qty
FROM order_table t1
WHERE ( "status" = 'SHP')
AND from_unixtime("ship_at"/1000000) BETWEEN (date_trunc('day', now()) + interval '-1170' MINUTE) AND (date_trunc('day', now()) + interval '-330' MINUTE)
AND "ship_at" =
(SELECT MAX("ship_at")
FROM order_table t2
WHERE t1."id"=t2."id")
GROUP BY 1,2;
现在,我无法找到一种方法来区分created_at列和shipped_at列,以计算要分派订单数量所花费的时间差。如果花费的时间少于6小时,则产品将处于IN TAT状态;如果花费的时间超过6小时,则产品将处于OUT TAT状态。
所需结果:
Client Name Qty_IN_TAT Qty_OUT_TAT
ACX 34 3
ADD 3423 21
AVC 234 34
任何帮助将不胜感激。