PostgreSQL 的 window函数
以例子来说明问题:
create table salaries(id integer,sal integer,site varchar(4));
insert into salaries values(1,100,'A');
insert into salaries values(1,200,'A');
insert into salaries values(2,300,'B');
insert into salaries values(2,400,'B');
insert into salaries values(3,500,'C');
insert into salaries values(3,600,'C');
SELECT id, sal, avg(sal) OVER (PARTITION BY site) from salaries;
id sal avg(sal)
1 100 150
1 200 150
2 300 350
2 400 350
3 500 550
3 600 550
这个功能有点像 group by ,但是它是出现在每一行的。
怎么看,都有点鸡肋,也许制作特殊的报表挺方便的。