2016-10-22 19 views
1

我有一個非常簡單的表:是否有可能有某種類別的組查詢在列中編號?

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 

回答

1

您可以使用group by子句每EnglishCount不同值的結果分開,然後應用到count(*)每組:

SELECT EnglishCount, COUNT(*) 
FROM  Score 
GROUP BY EnglishCount 
相關問題