\表中有字段a,b,c,d....
a b c .... 1 1 1 2 1 2 3 1 3 4 2 1 5 2 2 6 3 1 7 3 2 现在要根据字段b分组取得每个组里面a字段最大的纪录 结果应该是 a b c 3 1 3 5 2 2 7 3 2 ---------------------------------------------------------------------方法一:
select A.a,A.b,A.c from 表 A where A.a =
(select top 1 a from 表 where b = A.b order by c desc)
方法二:
select * from 表 a where a =(select max(a) from 表 where a.b=b)
-----------------------------------------
实例(owner)
SELECT han.* FROM tbl_ServiceHandlerInfo han
WHERE han.HandlerInfoID =(SELECT TOP 1 HandlerInfoID FROM tbl_ServiceHandlerInfoWHERE han.ServiceOrderID = ServiceOrderIDORDER BY HandlerInfoID DESC)