gpt4 book ai didi

sql - 获取具有多个值且至少其中一个为零的记录

转载 作者:行者123 更新时间:2023-12-03 01:55:52 25 4
gpt4 key购买 nike

Create table #Tbl
(
ID int not null,
Keyword nvarchar(max)
)
Insert into #Tbl Values ('0','Cryptography')
Insert into #Tbl Values ('1','Cryptography')
Insert into #Tbl Values ('4','Cryptography')
Insert into #Tbl Values ('0','SQL')
Insert into #Tbl Values ('0','SQL')
Insert into #Tbl Values ('3','Cloud Computing')
Insert into #Tbl Values ('6','Recursion')
Insert into #Tbl Values ('8','Recursion')
Insert into #Tbl Values ('0','Universe')
Insert into #Tbl Values ('0','Universe')
Insert into #Tbl Values ('7','Universe')

我需要获取具有多个 ID 并且至少有一个 ID 为零的标题。

所以预期的结果将是:

Cryptography
Universe

我尝试了以下查询,但无法添加“至少一个 id 为零”条件

select Keyword,COUNT(distinct id) from #Tbl
group by Keyword
having COUNT(distinct id)>1

我该如何继续?感谢您的帮助。

最佳答案

假设你的 ID 从 0 开始,下面的代码应该可以工作

select Keyword,COUNT(distinct id) from #Tbl
group by Keyword
having COUNT(distinct id)>1 and MIN(id) = 0

关于sql - 获取具有多个值且至少其中一个为零的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16945881/

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