1、postgresql 查询每组第一个
ROW_NUMBER () OVER (partition by 字段 ORDER BY 字段 DESC)
写法:SELECT ROW_NUMBER () OVER (partition by 字段 ORDER BY 字段 DESC) AS 字段别名 FROM 表名;
SELECT * FROM (SELECT *,ROW_NUMBER () OVER (partition by 字段 ORDER BY 字段 DESC) AS 字段别名(group_idx) FROM 表名) AA WHERE AA.group_idx='1'
2、postgresql 查询加序号
ROW_NUMBER () OVER (ORDER BY 字段 DESC)
写法:SELECT ROW_NUMBER () OVER (ORDER BY 字段 DESC) AS 字段别名 FROM 表名