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


猜你喜欢

转载自www.cnblogs.com/kerwincui/p/9289437.html