我有一个需要迁移到 Oracle 11g 的 MS Access PIVOT 查询。
TRANSFORM Format(Sum(tblOrderLine.ItemQtyCur), '#0.0') AS [The Value]
SELECT tblOrderLine.OrderStatus, tblOrderLine.OrdNo, tblOrderLine.OrdlNo, Format(Sum(tblOrderLine.ItemQtyCur), '#0.0') As SumConfQty
FROM tblOrder INNER JOIN (tblOrderLine LEFT JOIN tblArticle ON tblOrderLine.ItemId = tblArticle.ArtNo) ON tblOrder.OrdNo = tblOrderLine.OrdNo
GROUP BY tblOrderLine.OrderStatus, tblOrderLine.OrdNo, tblOrderLine.OrdlNo
PIVOT tblOrderLine.LastDate
我无法将其转换为 oracle 11g PIVOT。
谁能帮我这个....
编辑 :
会不会是这样。。。。。。
WITH pivot_data AS (
SELECT tblOrderLine.OrderStatus, tblOrderLine.OrdNo, tblOrderLine.OrdlNo, Format(tblOrderLine.ItemQtyCur, '#0.0') As SumConfQty
FROM tblOrder INNER JOIN (tblOrderLine LEFT JOIN tblArticle ON tblOrderLine.ItemId = tblArticle.ArtNo) ON tblOrder.OrdNo = tblOrderLine.OrdNo
GROUP BY tblOrderLine.OrderStatus, tblOrderLine.OrdNo, tblOrderLine.OrdlNo
)
SELECT * FROM pivot_data
PIVOT XML (
Format(Sum(tblOrderLine.ItemQtyCur), '#0.0')
FOR tblOrderLine.LastDate
IN (
SELECT tblOrderLine.LastDate
FROM tblOrder INNER JOIN (tblOrderLine LEFT JOIN tblArticle ON tblOrderLine.ItemId = tblArticle.ArtNo) ON tblOrder.OrdNo = tblOrderLine.OrdNo
GROUP BY tblOrderLine.OrderStatus, tblOrderLine.OrdNo, tblOrderLine.OrdlNo
)
);