postgresql sql查询结果添加序号列与每组第一个序号应用
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 表名