我工作的家庭作业,这是一个问题:错误在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:只有你可以“接受”,而不依赖于代表。 –