2014-03-19 96 views
1

是否可以在多個選擇中使用AS? 類似:AS多個選擇

SELECT O.order_id, Sum(Order_Tot) FROM 
(SELECT P.price * O.qty as Order_Tot FROM crOrdersToProducts O 
JOIN tblProducts P ON O.style_id = P.id) 
GROUP BY O.order_id 

試圖使用一個查詢的訂單ID顯示訂單總數。

回答

0
//try this query 

SELECT OT.order_id, Sum(OT.Order_Tot) FROM 
(SELECT O.order_id,P.price * O.qty as Order_Tot FROM crOrdersToProducts O 
JOIN tblProducts P ON O.style_id = P.id) as OT 
GROUP BY OT.order_id 
+0

甜!修正了錯誤:#1248 - 每個派生表都必須有自己的別名。謝謝 – user3437745