语法:ROW_NUMBER() OVER(PARTITION BY COLUMN ORDER BY COLUMN)
PARTITION BY 是分组的
ORDER BY 是排序的
例子:分组排序之后查第1页数据,每页20条
SELECT * FROM (
SELECT 列名称,COUNT(列名称) AS 新字段,ROW_NUMBER() OVER (ORDER BY COUNT(列名称) DESC) AS RowNumber
FROM 表名称 WHERE 查询条件 GROUP BY 列名称
) T
WHERE T.RowNumber BETWEEN 1 AND 20