我正在准备以下字段的表格。
我想仅在Account_Id组内的Invalid_vod中获得类似于状态的输出
Account_Id Address_Id Status
AC001 ADD12345 Invalid_vod
AC003 ADD12348 Invalid_vod
AC003 ADD12349 Invalid_vod
我当时是这样做的,但无法获得预期的结果。
select [Account_Id],[Address_Id],[Status]
from [DBFile]
group by [Account_Id],[Address_Id],[Status]
having [Status] = 'Invalid_vod'
您可以COUNT
为此使用窗口版本:
;with cte as (
select [Account_Id], [Address_Id], [Status],
count(case when [Status] <> 'Invalid_vod' then 1 end)
over (partition by [Account_Id]) AS cnt
from [DBFile]
)
select [Account_Id], [Address_Id], [Status]
from cte
where cnt = 0
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句