SQLSERVER 排序函数(2005以后版本)
SQLSERVER 取每组的前几条记录
SELECT *
FROM(
SELECT id, 字段1,字段2,字段3
FROM(
SELECT id, 字段1,字段2,字段3
ROW_NUMBER() OVER (
PARTITION BY 分组字段 ORDER BY 排序字段 desc
) as RANK
FROM 表1 as ua WHERE 条件语句)T
WHERE T.RANK <= 4
) as RANK
FROM 表1 as ua WHERE 条件语句)T
WHERE T.RANK <= 4