符合条件的分组

阿维吉特

我正在准备以下字段的表格。

在此处输入图片说明

我想在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'
乔治·贝索斯(Giorgos Betsos)

您可以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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章