按查询分组和 SQL Server 2008
我有这个查询
select SUM(Qty) as Qty
from WorkTbl group by Status
having Status = 'AA' or Status = 'BB'
这个查询返回 2 行(100 和 500)
如何对这两行求和?
I have this query
select SUM(Qty) as Qty
from WorkTbl group by Status
having Status = 'AA' or Status = 'BB'
this query returns 2 rows (100 and 500)
How to sum those 2 rows ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
取出
GROUP BY
,并使用WHERE
而不是HAVING
?或者,如果您的查询有更多内容,并且您希望保留大部分当前结构,请将其放入子查询(或 CTE)中:(
我们必须在末尾包含
t
,因为from 子句中的每个行源都必须有一个名称 - 它可以是任何名称)Take out the
GROUP BY
, and useWHERE
instead ofHAVING
?Or, if there's more to your query, and you wish to keep most of the current structure, put it into a subquery (or a CTE):
(We have to include the
t
at the end, since every row source in the from clause has to have a name - it could be anything)