gpt4 book ai didi

sql - 是否可以使用某种组查询对列中的数字进行分组?

转载 作者:行者123 更新时间:2023-12-03 19:31:46 25 4
gpt4 key购买 nike

我有一个非常简单的表:

CREATE TABLE "Score"(
"Id" varchar primary key not null ,
"EnglishCount" int ,
"RomajiCount" int )


有没有一种我可以运行的查询,它将显示给我:

   how many rows have EnglishCount = 0,
how many rows have EnglishCount = 1,
how many rows have EnglishCount = 2,
how many rows have EnglishCount = 3,
how many rows have EnglishCount = 4,
etc ...


这是我希望获得的输出:

Count    Instances
0 1
1 2
3 1
4 5
5 2

最佳答案

您可以使用group by子句按EnglishCount的不同值分隔结果,然后将count(*)应用于每个组:

SELECT   EnglishCount, COUNT(*)
FROM Score
GROUP BY EnglishCount

关于sql - 是否可以使用某种组查询对列中的数字进行分组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40190985/

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