例:    stu表:
          school  class  nation  total   ...
        清华       1班     汉族       35
        清华       2班     汉族       30
        清华       2班     回族       3
        清华       2班     藏族       2
        北大       1班     壮族       35
结果:
        school   class   nation  ...
       清华        1班     汉族
                    2班      回族
                             汉族
                             藏族
        北大        1班      壮族

解决方案 »

  1.   

    partition by 字段 order by 字段 ....
      

  2.   

    over partion by 的效果也只能是
    1 北大 1班 35
    2 清华 1班 35
    3 清华 2班 35
    4 清华 2班 35
    5 清华 2班 35想把重复的合并 用sql来实现不现实 就算费劲写出来 效率也不高
    这个要在程序里边处理才对,从技术角度看,从逻辑角度看,都应该这样
      

  3.   

    WITH TEST AS (
    SELECT '清華' AS school,'1班' as classs,'漢族' as nation,'35' as total from dual
    union all
    SELECT '清華' AS school,'2班' as classs,'漢族' as nation,'30' as total from dual
    union all
    SELECT '清華' AS school,'2班' as classs,'回族' as nation,'3' as total from dual
    union all
    SELECT '清華' AS school,'2班' as classs,'藏族' as nation,'2' as total from dual
    union all
    SELECT '北大' AS school,'1班' as classs,'壮族' as nation,'35' as total from dual
    )
    select case when school = ps then '' else school end as school,
           case when classs = pc then '' else classs end as classs,
           nation,
           total from(
    select lag(school)over(partition by school order by school) as ps,lag(classs)over(partition by school order by school,classs) as pc,test.* from test)=================================================
    1 清華 1班 漢族 35
    2 2班 漢族 30
    3 回族 3
    4 藏族 2
    5 北大 1班 壮族 35