last_value()函数如果不写partition by()为什么取得不是整体的最后一个?

last_value()函数如果不写partition by()不应该是像first_value()取整体的第一个一样取整体的最后一个吗?为什么仍是取以deptno分区后的最后一个?

 deptno |   sal   
--------+---------
      0 | 5000.00
     20 |  800.00
     20 | 1600.00
     20 | 2975.00
     30 | 1600.00
     30 | 3000.00
(6 rows)

bank=# select distinct deptno,first_value(sal) over(order by deptno) from emp;
 deptno | first_value 
--------+-------------
     30 |     5000.00
      0 |     5000.00
     20 |     5000.00
(3 rows)

bank=# select distinct deptno,last_value(sal) over(order by deptno) from emp;
 deptno | last_value 
--------+------------
     30 |    3000.00
      0 |    5000.00
     20 |    2975.00
(3 rows)

last_value()默认统计范围是 rows between unbounded preceding and current row,也就是取当前行数据与当前行之前的数据的比较。

那么,如何像first_value()那样直接在每行数据中显示最后的那个数据呢?

在order by 条件的后面加上语句:rows between unbounded preceding and unbounded following