【发布时间】:2020-01-25 18:16:30
【问题描述】:
mysql> select * from FinalTable;
+------+-------+-------+---------------------+
| id | name | state | timestamp |
+------+-------+-------+---------------------+
| 12 | name1 | TX | 2020-01-25 11:29:36 |
| 14 | name3 | CA | 2020-01-25 11:29:36 |
| 14 | name3 | TX | 2020-01-25 11:29:36 |
| 12 | name1 | CA | 2020-01-25 11:29:36 |
| 13 | name2 | TA | 2020-01-25 11:29:36 |
| 14 | name3 | CA | 2020-01-25 11:29:36 |
+------+-------+-------+---------------------+
我正在查看输出查询,其响应为:
I2 name1 TX 2020-01-25 11:29:36 CA 2020-01-25 11:29:36
当我运行查询时,
select id,name,state,timestamp,
lead(state,1) over (partition by id order by timestamp asc) out_state,
lead(timestamp,1) over (partition by id order by timestamp asc) out_timestamp
from FinalTable
ERROR 1064 (42000): 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 '(partition by id order by timestamp asc) out_state,
lead(timestamp,1) over (part' at line 2
还可以在数据库中创建毫秒而不是秒的时间戳吗? 我正在使用 CURRENT_TIMESTAMP。
【问题讨论】:
-
你的 MySql 版本是多少?
-
Ver 14.14 发行版 5.7.28 Ubantu
标签: mysql sql window-functions mysql-5.7