pgsql中over函数的应用

-- sum() over(partition by ... order by ...)
SELECT len/sum(len)over(partition by road_id) param from rs;

-- min() over(partition by ... order by ...)
SELECT min(len)over(partition by road_id) param from rs;

-- max() over(partition by ... order by ...)
SELECT max(len)over(partition by road_id) param from rs;

-- row_number() over(partition by ... order by ...)
SELECT row_number() over(partition by road_id) param,road_id from rs;

-- rank() over(partition by ... order by ...)
SELECT rank()over(partition by road_id ORDER BY len) param,road_id from rs;

-- dense_rank() over(partition by ... order by ...)
SELECT dense_rank()over(partition by road_id ORDER BY len) param,road_id from rs;

-- count() over(partition by ... order by ...)
SELECT count() over(partition by road_id) param,road_id from rs;

posted @ 2022-12-19 10:25  懂得归零  阅读(649)  评论(0编辑  收藏  举报