一条语句为找出每一个分类的前3条记录
表:
[Resource_Resource]
字段:
[ResourceId] 主键,标识列
[ResourceName] 名称
[UserId] 用户编号
要求:查询每个用户的前三条记录
SQL2005的写法:
1WITH newTable AS (
2 SELECT * ,RANK() OVER(PARTITION BY userId ORDER BY ResourceId) RANK FROM Resource_Resources
3)
4SELECT * FROM newTable WHERE RANK < 4
2 SELECT * ,RANK() OVER(PARTITION BY userId ORDER BY ResourceId) RANK FROM Resource_Resources
3)
4SELECT * FROM newTable WHERE RANK < 4