sql server分组查询并查询出每组的前几行数据

select [PR_ID]
      ,[PR_TypeID]
      ,[PR_Name]
      ,[PR_PicUrl]
      ,[PR_PicName]
      ,[PR_PLID]
from(select [PR_ID]
      ,[PR_TypeID]
      ,[PR_Name]
      ,[PR_PicUrl]
      ,[PR_PicName]
      ,[PR_PLID],rn=ROW_NUMBER() over(partition by PR_TypeID order by PR_ID desc) from BT_ProductInfo where PR_PLID='2')t
where rn<=5

posted on 2013-12-26 10:09  西湖雨  阅读(477)  评论(0)    收藏  举报

导航