gpt4 book ai didi

SQL - 按两位分组

转载 作者:行者123 更新时间:2023-12-04 19:09:39 26 4
gpt4 key购买 nike

我有一个包含一位列的 SQL 表。如果只有一个位值(在我的例子中是 1)出现在表的行中,我如何制作一个 SELECT 语句来显示,例如,表中两个位值的出现,即使另一个没有出现?这是我想要达到的结果:

+----------+--------+
| IsItTrue | AMOUNT |
+----------+--------+
| 1 | 12 |
| 0 | NULL |
+----------+--------+

我已经尝试用谷歌搜索答案但没有成功,因为英语不是我的母语而且我不太熟悉 SQL 行话。

最佳答案

select IsItTrue, count(id) as Amount from 
(select IsItTrue, id from table
union
select 1 as IsItTrue, null as id
union
select 0 as IsItTrue, null as id) t
group by bool

关于SQL - 按两位分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27475386/

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