表:student
属性:id 姓名 年级 班级 民族 家庭所在省
要实现以下效果:
  一年级 一班 5个民族 7个省份
  一年级 二班 3个民族 6个省份
  二年级 一班 5个民族 9个省份
  二年级 二班 3个民族 8个省份请问能否通过一个简洁的使用oracle分析函数的sql来实现?怎么实现?
请高手帮忙!

解决方案 »

  1.   

    select 年级, 班级,count(distinct 民族 ),count(distinct 家庭所在省 )
    from student 
      

  2.   

    1楼的语句加上group by 年级,班级
      

  3.   

    select 年级, 班级,count(distinct 民族 ),count(distinct 家庭所在省 ) 
    from student 
    group by 年级,班级
    不用分析函数~~
      

  4.   


    select 年级 ,班级,count(distinct 民族) over(partition by 年级,班级) 民族
    ,count(distinct 家庭所在省) over(partition by 年级,班级) 家庭所在省
    from tb