2016-12-27 74 views
0

選擇重複計數我有一個看起來像這樣的數據:超過兩列

school  district  crs_sbj crs_num crs_sec 
CANYON HIGH IRON DISTRICT ENGL  2010  213 
CANYON HIGH IRON DISTRICT ENGL  2010  214 
CANYON HIGH IRON DISTRICT ENGL  1010  110 
CANYON HIGH IRON DISTRICT MATH  1010  400 
WAYNE HIGH WAYNE DISTRICT MATH  1010  321 
WAYNE HIGH WAYNE DISTRICT MATH  1010  322 
WAYNE HIGH WAYNE DISTRICT ENGL  1010  500 

我想算在每個單獨的高中提供的獨特的類。 例如,我想看看:

count school 
    3  CANYON HIGH 
    2  WAYNE HIGH 

我怎麼會去這樣做呢?我理解一列的概念,但是兩個怎麼樣?

+0

輸入如何與預期輸出相關? –

回答

1

試試這個:

select school, count(distinct crs_num) _count 
from table 
group by school; 
0
Select School, count(distinct crs_num) 
from table 
group by School 
0

我不確定什麼構成一個獨特的類。

; with aardvark (select distinct school, district, crs_sbj, crs_num 
    from T) 
select district, school, count(*) 
from aardvark 
group by school, district 

由於可以跨地區使用同一學校名稱,因此我在分組中包括該地區。