其他列有什么要求,比如要是col1中重复值中col2最大值的

解决方案 »

  1.   

    没有主键??
    select * from tablename a
    where col2=(select min(col2) from tablename where col1=a.col1)
    and col3=(select min(col3) from tablename where col1=a.col1 and col2=a.col2)
      

  2.   

    select O.col1,(select top 1 col2 from [table] where col1=O.col1)
           ,(select top 1 col2 from [table] where col1=O.col1)
    from [table] O
    group by O.col1
      

  3.   

    是这样的
    select O.col1,(select top 1 col2 from [table] where col1=O.col1)
           ,(select top 1 col3 from [table] where col1=O.col1)
    from [table] O
    group by O.col1
      

  4.   

    select sn=identity(int,1,1),* into #t from [table]
    select a.col1,a.col2,a.col3 from #t a where sn=(select min(sn) from #t b where b.col1=a.col1)  --取相同col1的第一行,这样好处就是不用担心其他列有重复的值