時間這將讓大部分......包括在每通道輸入/輸出多個標誌以及每個登錄/退出時間段內有多少次交易。一旦你得到了這個結果,你可以從THIS查詢獲得活動車道/會話總數與任何累積值......例如總共18次車輛登錄/註銷總銷售交易總次數,或總共多少車道是開放的,並且佔了這種銷售活動。
由於group by在lane,signon/off,我只是將MIN()應用於小時,分鐘和秒鐘,這對每個註冊/關閉會話都是一個常數。
SELECT
PreQuery.Lane,
PreQuery.SignedOn,
PreQuery.SignedOff,
MIN(datediff(hour, PreQuery.SignedOn, PreQuery.SignedOff)) as hours,
MIN(datediff(minute, PreQuery.SignedOn, PreQuery.SignedOff)) as minutes,
MIN(datediff(second, PreQuery.SignedOn, PreQuery.SignedOff)) as seconds,
COUNT(*) as NumOfSales
from
(SELECT
T1.Lane,
T1.TransactionDate SignedOn,
MIN(T2.TransactionDate) as SignedOff
from
Trans1 T1
LEFT JOIN Trans1 T2
ON T1.Lane = T2.Lane
AND T2.TransactionType = "SignOff"
AND T2.TransactionDate > T1.TransactionDate
where
T1.TransactionType = "SignOn"
group by
T1.Lane,
T1.TransactionDate) PreQuery
LEFT Join Trans1 T3
on PreQuery.Lane = T3.Lane
AND T3.TransactionType = "Sale"
AND T3.TransactionDate BETWEEN PreQuery.SignedOn AND PreQuery.SignedOff
GROUP BY
PreQuery.Lane,
PreQuery.SignedOn,
PreQuery.SignedOff
這功課嗎? – dwo
不,這不是作業 – Azat
你有什麼試圖解決它? – dwo