我工作的家庭作業,這是一個問題:錯誤在SQL集團通過
創建從出貨量,ShipItems和品牌表返回行的視圖名爲ShipItemsBrands。
該視圖應該從貨物表中返回這些列:ShipmentID,ShipmentOrderDate,TaxAmount和ShipDate。
此視圖應從ShipItems表中返回這些列:ShipItemPrice,ShipItemDiscountAmount,FinalPrice(從項目價格減去折扣金額),Quantity和ItemTotal(項目的計算總數)。
此視圖應返回品牌表中的BrandName列。
這裏是我的代碼:
CREATE VIEW ShipItemsBrand
AS
SELECT
sh.ShipmentID, sh.ShipmentOrderDate, sh.TaxAmount, sh.ShipDate,
si.ShipItemPrice, si.ShipItemDiscountAmount,
SUM(si.ShipItemPrice - si.ShipItemDiscountAmount) As FinalPrice,
si.Quantity,
SUM((si.ShipItemPrice - si.ShipItemDiscountAmount) * si.Quantity) AS ItemTotal,
b.BrandName
FROM
Brands AS b
JOIN
ShipItems AS si ON b.BrandID = si.BrandID
JOIN
Shipments AS sh ON si.ShipmentID = sh.ShipmentID
GROUP BY
sh.ShipmentID
我收到錯誤代碼:
,因爲它不包含在列「Shipments.ShipmentOrderDate」在選擇列表中無效集合函數或GROUP BY子句。
是否需要將sh.ShipOrderDate
添加到GROUP BY
?如果是這樣,爲什麼呢?
沒問題。 *(ps:upvoting也是一種表達感謝的方式,「接受」表示你已經選擇了一種解決方案,這有助於他人理解什麼對你有幫助,同時他們也在尋找類似的答案。)* https://stackoverflow.com/help/someone-answers –
我upvoted,但沒有代表它顯示 –
代表哦,好的,謝謝。 NB:只有你可以「接受」,而不依賴於代表。 –