使用滞后函数在MySQL中添加列
我需要一列,使我可以与上一行和当前行的列的差异。我能够使用Select语句来实现这一目标。 之后,使用
SELECT *,`open` - LAG(`close`,1,`open`) over (order by `open`) as `previous_day_close` FROM backtestData.NSE_RELIANCE ;
在运行查询
I need a column that gives me the difference of a column of a previous row and current row. I am able to achieve this using a select statement.
Using
SELECT *,`open` - LAG(`close`,1,`open`) over (order by `open`) as `previous_day_close` FROM backtestData.NSE_RELIANCE ;
The table looks like this after running the query
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个 view 。
窗口函数不能在生成的列中使用,但是您可以查看显示的查询。
Create a VIEW.
Window functions can't be used in generated columns, but you can make a VIEW of the query you show.