gpt4 book ai didi

sql - 按列中没有空值分组

转载 作者:行者123 更新时间:2023-12-02 00:42:30 24 4
gpt4 key购买 nike

如果我执行下面的查询

select a, bar.c from foo
left join bar on foo.id = bar.foo

我得到了这些结果

a   c
----------
1 1
1 3
1 null

2 1
2 2

3 1
3 null
3 3
3 4

现在我想按 a 对这些值进行分组,但只有当 b 没有单个空值时,结果才得到 a=2 .我该怎么做?

最佳答案

你可以使用:

select a
from foo left join
bar
on foo.id = bar.foo
group by a
having count(*) = count(bar.c);

关于sql - 按列中没有空值分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45815530/

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