我有一个非常简单的表:
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/