表Table T_Table 

Name Varchar2(11), 
Property Varchar2(11) 
) 表中的数据: 
Name    Property 
liu    a 
liu    b 
liu    c 
wang    a 
wang    b 
zhang  b 用一个SQl输出为: 
Name    Property 
liu    a 
wang    a 
zhang  b 
即每人只输出随便一个属性就可以 
这样的SQL怎么写?

解决方案 »

  1.   

    select name,property
    from 
    (
    select name,property,row_number()over(partition by name,property order by name) nn
    from T_Table )
    where nn=1
      

  2.   

    前面一个帖子回复不行吗?
    select Name,Property
    from (select t.*,row_number() over(partition by Name) rn from T_Table  t) 
    where rn=1 

    这个语句在你的电脑上执行有错误吗?
      

  3.   

    select a ,(select Property  from T_Table  where name =b.a and rownum=1)from (select distinct Name  a from   T_Table ) b 
      

  4.   

    --cosio 分组时多了一列哈,这样试一下
    select name,property
    from 
    (
    select name,property,row_number()over(partition by name order by name) nn
    from T_Table )
    where nn=1