postgresql分组后获取第一条数据

-- 根据编号分组取第一条数据
select * from table t where t.no=(select max(no) from table t1 where t1.no=t.no)


-- 根据编号分组后取第一条数据
SELECT * FROM 
    (SELECT ROW_NUMBER() OVER (partition BY no ORDER BY no) rowId,* 
    from table) t
WHERE rowId=1


 

posted @ 2018-07-10 15:41  kerwin cui  阅读(6884)  评论(0编辑  收藏  举报