[英]Select distinct count over two columns
I have data that looks like this: 我有看起来像这样的数据:
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
I want to count the unique classes offered at each individual high school. 我想计算每所高中提供的独特课程。 For example, I want to see:
例如,我想看:
count school
3 CANYON HIGH
2 WAYNE HIGH
How would I go about doing this? 我将如何去做呢? I understand the concept of one column, but how about two?
我了解一栏的概念,但是两栏呢?
Try this: 尝试这个:
select school, count(distinct crs_num) _count
from table
group by school;
Select School, count(distinct crs_num)
from table
group by School
I am unsure what constitutes a unique class. 我不确定什么是独特的课程。
; with aardvark (select distinct school, district, crs_sbj, crs_num
from T)
select district, school, count(*)
from aardvark
group by school, district
Since the same school name can be used across districts, I included the district in the grouping. 由于可以在各地区使用相同的学校名称,因此我将地区包括在分组中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.