是否有更好,更有效的方式来编写这段代码:
SELECT
Customer_ID,
Location_Number,
Customer_Type,
Sales_Amount,
SUM(Sales_Amount *
(SELECT SUM(Sales_Amount) / SUM(Sales_Qty)
FROM Sales
)) AS Percentage_Sales
FROM Sales
WHERE Shipping_Price > 0 AND Customer_Type is not null
GROUP BY
Location_Number,
Customer_Type,
Customer_ID,
这只是我编写的一些示例代码,但我想专注于" Percentage_Sales"计算列,其中我基本上在SELECT子句中包含一个子查询。如果说我想创建大约5-10个这些计算列,可能还有更复杂的子查询,这是一个好的做法还是有更好的方法来做到这一点?
谢谢!