gpt4 book ai didi

sql-server - SQL Server 上的“无法对聚合或子查询执行聚合函数”错误

转载 作者:行者123 更新时间:2023-12-03 13:20:36 25 4
gpt4 key购买 nike

Select A.nEvrakKalemID As ID, 
A.cEvrakKalem As [Inventory Name],
SUM((IsNull((Select SUM(B.nMiktar) Where B.nEvrakTip = 3 or B.nEvrakTip = 7),0)) - (IsNull((Select SUM(B.nMiktar) Where B.nEvrakTip = 4 or B.nEvrakTip = 8),0))) As Inventory
From MasrafAnaliz.dbo.EvrakKalem A
Left Outer Join MasrafAnaliz.dbo.EvrakKalemHareket B
On B.nKodEvrakKalem = A.nEvrakKalemID
Group By A.nEvrakKalemID, A.cEvrakKalem, B.nMiktar
Order By A.nEvrakKalemID

在上面的问题中,我想总结Inventory列,并根据nEvrakKalemID列对其进行分组。但它不起作用。预先感谢您的帮助。

最佳答案

试试这个:

Select A.nEvrakKalemID As ID, 
A.cEvrakKalem As [Inventory Name],
(SUM(CASE WHEN B.nEvrakTip = 3 or B.nEvrakTip = 7
THEN (IsNull(B.nMiktar,0))
ELSE 0
END) -
SUM(CASE WHEN B.nEvrakTip = 4 or B.nEvrakTip = 8
THEN IsNull(B.nMiktar,0)
ELSE 0
END)) As Inventory
From MasrafAnaliz.dbo.EvrakKalem A
Left Outer Join MasrafAnaliz.dbo.EvrakKalemHareket B On B.nKodEvrakKalem = A.nEvrakKalemID
Group By A.nEvrakKalemID, A.cEvrakKalem, B.nMiktar
Order By A.nEvrakKalemID

关于sql-server - SQL Server 上的“无法对聚合或子查询执行聚合函数”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43250093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com