取出分组的头一条记录

取出分组的头一条记录


SELECT * FROM
(

Select 
  OrderId,Pro_Id,TotalPro_Count,RowCnt = ROW_NUMBER()  OVER(PARTITION BY OrderId ORDER BY TotalPro_Count desc)
From
(
SELECT OrderId, Pro_Id, Sum(Pro_Count) as TotalPro_Count FROM Order_Pro_List
WHERE  OrderId IN(2011081013367,2011072613014,2011082315204,2011082315779)

GROUP BY OrderId,Pro_Id --HAVING COUNT(Pro_Id) > 1

)
 AS t
 
)
AS t2

WHERE RowCnt = 1

ORDER BY OrderId

posted @ 2011-12-22 11:42  zzljh  阅读(194)  评论(0编辑  收藏  举报