以下ORDER BY
子句导致错误。如何在ORDER BY
子句中引用 TotalPrice 列:
SELECT * FROM
(
SELECT O.OrderID,
(SELECT SUM(SubTotal) FROM DB_OrderDetails OD WHERE OD.OrderID = O.OrderID) AS TotalPrice,
ROW_NUMBER() OVER (ORDER BY TotalPrice) AS RowNum
FROM DB_Orders O
) Orders