我要表:
DeviceInstace
和Device
它们与Foreign Key
DeviceInstance.DeviceId=Device.Id
相关联
我有SQL查询:
select d.CatalogNo,d.Manufacturer,d.Name, sum(quantity)
from DeviceInstance di
full join Device d
on d.Id=di.DeviceId
group by di.DeviceId
我需要做一些包含以下内容的摘要:
但我面临一些Grouping by
次发布。
我尝试拒绝这样的错误:
Column 'Device.CatalogNo' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
我知道我可以按CatalogNo
进行分组,但随后十个数量的总和会返回错误的数字。
有谁能建议我如何修复它?
答案 0 :(得分:3)
只需修改GROUP BY子句:
group by d.DeviceId, d.CatalogNo,d.Manufacturer,d.Name
答案 1 :(得分:1)
您需要在分组条款中添加d.CatalogNo,d.Manufacturer
试试这个
select d.CatalogNo,d.Manufacturer,d.Name, sum(quantity)
from DeviceInstance di
full join Device d
on d.Id=di.DeviceId
group by d.Name, d.CatalogNo,d.Manufacturer