在接下来的7天内找到最大值
我有一个SQL表:
ID | 日期 | 值 |
---|---|---|
1 | 01/01/2019 | 50 |
1 | 01/13/2019 | 24 |
1 | 01/19/2019 | 53 |
2 | 01/05/2019 | 50 |
2 | 01/11/11/11/2019 | 24 |
2 | 01/24/2019/2019 | 53 |
我想创建一个新列,该列计算在接下来的14天内按ID分组的最大值。如果当前行中的日期与下一个日期之间的差异大于14,请返回无或null。
新表将是:
ID | 日期 | 值 | MAX_14 |
---|---|---|---|
1 | 01/01/01/50 | 1 | 50 |
1 | 01/13/2019 | 24 | 53 |
1 | 01/19/2019 | 53 | NONE |
2 | 01/05/2019 | 50 | 50 2 50 |
2 | 01/11/11/2019 | 24 | 53 24 53 |
2 | 01/24/2019 | 53 | 无 |
I have a SQL table:
id | date | value |
---|---|---|
1 | 01/01/2019 | 50 |
1 | 01/13/2019 | 24 |
1 | 01/19/2019 | 53 |
2 | 01/05/2019 | 50 |
2 | 01/11/2019 | 24 |
2 | 01/24/2019 | 53 |
I want to create a new column that computes that max value over the next 14 days grouped by id. If the difference between the date in the current row and the next is greater than 14, return None or Null.
The new table will be:
id | date | value | max_14 |
---|---|---|---|
1 | 01/01/2019 | 50 | 50 |
1 | 01/13/2019 | 24 | 53 |
1 | 01/19/2019 | 53 | None |
2 | 01/05/2019 | 50 | 50 |
2 | 01/11/2019 | 24 | 53 |
2 | 01/24/2019 | 53 | None |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以为此使用子问题:
You can use a sub-query for this: