gpt4 book ai didi

sql - SQL查询麻烦SQLite

转载 作者:行者123 更新时间:2023-12-03 18:25:45 24 4
gpt4 key购买 nike

4列

| day of year | year | user A | user B |

1 1 john ron
2 1 ron john
1 2 john kyle


我需要计算用户出现在UserA列或UserB列中的次数

按UserA列分组不是很简单,我需要计算john从UserA和UserB列中总共出现了多少次

预期产量

john 3
ron 2
kyle 1

最佳答案

您似乎想要union all

select user, count(*) counts from
(
select [user A] as user from table t
union all
select [user B] as user from table t
)a
group by user

关于sql - SQL查询麻烦SQLite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49376674/

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