gpt4 book ai didi

SQL group by NULL/NOT NULL

转载 作者:行者123 更新时间:2023-11-29 14:19:53 24 4
gpt4 key购买 nike

id name facebookid linkedinid  googleid                                                 
-- ---- ---------- ---------- --------
1 john 123456xde NULL 345ft566
2 peter NULL NULL 4563erf
3 suma df3466 yh4566 NULL
4 rick NULL 34Nh6 NULL
5 ronny NULL NULL NULL
6 susan NULL NULL 3456

我想知道有多少用户使用 linkedin、google、facebook 注册,以及有多少用户根本没有连接任何网络。

预期结果:

facebook linkedin google direct
-------- -------- ------ -----
2 2 3 1

SQL 查询会很棒,但我希望了解如何处理它。

谢谢

编辑:

我试过了

SELECT count(facebookid), count(linkedinid), count(googleid) FROM user;

最佳答案

试试这个:

    select 
count(facebookid) "linkedinid",
count(linkedinid) "linkedinid",
count(googleid) "googleid",
count(case
when facebookid is null
and linkedinid is null
and googleid is null then 1 else null end) direct
from your_table

关于SQL group by NULL/NOT NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32603283/

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