這是我當前的查詢:SQL如何申請DateDiff的兩個不同的where子句
select serial_number, order_number,
(select TOP 1 PRODUCT_ID from PS_ORD_LINE PL
where PL.ORDER_NO = WO.order_number
and CAT_DESCR = 'SYSTEM' and ORD_LINE_STATUS = 'O'
ORDER BY ORDER_INT_LINE_NO) as model,
(select datediff(minute, min(complete_time), min(start_time))
from TRACKED_OBJECT_HISTORY TOH1
where TOH1.op_name IN ('Assembly', 'Pre-Final')
and TOH1.tobj_key = TOH.tobj_key) as waiting_time1,
from UNIT U
left join WORK_ORDER WO on U.order_key = WO.order_key
left join TRACKED_OBJECT_HISTORY TOH on TOH.tobj_key = U.unit_key
where WO.creation_time > '5/1/12' and WO.creation_time < '7/31/12'
group by serial_number, order_number, tobj_key
與DateDiff
中間的部分是我的問題。
所以Assembly
和Pre-Final
是單位掃描兩個不同的站的名稱。Assembly
通常是第一線,通過Pre-Final
緊接着。
我想要做的是計算單位掃描出Assembly
之後和該單位掃描到Pre-Final
之後的經過時間。 complete_time
馬克當一個單位被掃描出站,並start_time
是當它在掃描真實。
現在,我的查詢不起作用,因爲這兩個start_time
和complete_time
指Assembly
,因爲它是第一站。不過,我想要complete_time
來參考Assembly
,而我想start_time
指的是Pre-Final
。
我應該怎麼做呢?
對不起,標題應該是datediff,而不是我的壞 – user1558927 2012-08-09 23:38:31