现在数据结构大概如下:M           P
1           1
1           2
1           3
2           1
3           1
3           2
4           1最终的结果要求为:
M           P
1           3
2           1
3           2
4           1即要求M要唯一,P为当前M中最大的.
请各位帮忙,谢谢了.

解决方案 »

  1.   

    SELECT MAX(P) AS P FROM TABLE GROUP BY M
      

  2.   


    select * from tb a where not exists(
    select 1 from tb where M=a.M and P>a.P
    )
      

  3.   

    select m , max(p) p from tb group by m
      

  4.   

    SELECT * FROM
    (SELECT DISTINCT M FROM tb) a
    CROSS APPLY
    (SELECT TOP(1) P FROM tb WHERE M = a.M ORDER BY P DESC) b
      

  5.   

    select * from tb t where =(select max(p) from tb where m=t.m)
      

  6.   

    select m , max(p) p from tb group by m
    楼上几位的都可以.....请LZ测试一下吧