如何解决Lag函数在mysql workbench 8.0中不起作用
SELECT created_at,grand_total,lag(grand_total,1) over (order by o.grand_total desc) as 'lag'
FROM sales_flat_order;
错误代码:1064。您的SQL语法有错误;检查 与您的MySQL服务器版本相对应的手册 在'((按o.grand_total desc排序)附近用作'滞后'FROM的语法 sales_flat_order”位于第2行0.016秒
代码在以下位置失败:超过**(**由o.grand_total desc排序)
解决方法
检查您使用的是哪个MySQL版本
Simulate lag function in MySQL
MySql using correct syntax for the over clause
,您可以使用相关子查询:
SELECT created_at,grand_total,(select grand_total
from sales_flat_order sfo2
where sfo2.grand_total > sfo.grand_total
order by sfo2.grand_total asc
limit 1
)
FROM sales_flat_order sfo;
请注意,lag()
降序排序通常称为“线索”。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。