我刚开始考虑左外连接,我正在练习 PIVOTS。
我想知道是否可以将此查询转换为数据透视表?
SELECT mydrawercustomer.customerface,
mydrawerordertype.ordertypeface,
mydrawerorder.LM,
Datediff(hour, a1.playdate, a2.playdate) AS [RunningTime1],
Datediff(hour, a2.playdate, a3.playdate) AS [RunningTime2],
Datediff(hour, a3.playdate, a4.playdate) AS [RunningTime3],
Datediff(hour, a1.playdate, a4.playdate) AS [RunningTime4]
FROM mydrawerorder
LEFT OUTER JOIN mydrawercustomer
ON mydrawerorder.customerKEY = mydrawercustomer.customerKEY
LEFT OUTER JOIN mydrawerorderactivity a1
ON mydrawerorder.orderKEY = a1.orderKEY
AND a1.activityKEY = 1
LEFT OUTER JOIN mydrawerorderactivity a2
ON mydrawerorder.orderKEY = a2.orderKEY
AND a2.activityKEY = 2
LEFT OUTER JOIN mydrawerorderactivity a3
ON mydrawerorder.orderKEY = a3.orderKEY
AND a3.activityKEY = 3
LEFT OUTER JOIN mydrawerorderactivity a4
ON mydrawerorder.orderKEY = a4.orderKEY
AND a4.activityKEY = 4
INNER JOIN mydrawerordertype
ON mydrawerorder.ordertypeKEY = mydrawerordertype.ordertypeKEY
ORDER BY mydrawercustomer.customerface,
mydrawerordertype.ordertypeface,
mydrawerorder.LM,
a1.playdate
我不是要求你为我解决我的挑战,但我只是请求帮助开始将这种类型的左外连接查询转换为 PIVOT。