我有两个表格:
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
我需要做一个小总结,其中包括以下内容:
- 目录号
- 制造商
- 设备名称
- 设备数量(这些设备ID的数量列值之和)
我尝试的所有方法都会给我返回像这样的错误信息:
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
分组,但是数量的总和会返回错误的数字。
有人能建议我如何修复它吗?