为什么我不能在 MySQL 中使用无限跟随?
我可以使用 unbounded preceding 而不会对同一查询产生任何问题。
SELECT deptno,
ENAME
SAL,
HIREDATE,
last_value(HIREDATE) OVER (
PARTITION BY deptno
ORDER BY HIREDATE
ROWS UNBOUNDED FOLLOWING
)
FROM emp2
ORDER BY DEPTNO, HIREDATE;
输出:
[42000][1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
FOLLWOING ) FROM emp2 ORDER BY DEPTNO, HIREDATE
at line 2
最佳答案
有两种方法可以使用 window frame specification :
- 显式指定下帧边界并隐式使用
当前行
作为上限 - 明确指定下限和上限
查看手册:
The frame_extent value indicates the start and end points of the frame. You can specify just the start of the frame (in which case the current row is implicitly the end) or use BETWEEN to specify both frame endpoints
你要写的是这样的:
SELECT
deptno, ename, sal, hiredate,
last_value (hiredate) OVER (
PARTITION BY deptno
ORDER BY hiredate
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
)
FROM emp2
ORDER BY deptno, hiredate
关于mysql - 为什么 MySQL 中没有无限跟随?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51575446/