Oracle SQL-以最大值更新重复
我正在寻找一个更新语句,它将更新具有重复时间戳的行,并仅更新在“持续时间”列处最大值的行,我可以在Oracle SQL或PL/SQL中使用。
使用
示例 | 1 | 的 | 可以 |
---|---|---|---|
这 | 是 | 表 | 一个 |
| | | |
| | | |
| | | |
Result expected:
| | | |
---|---|---|---|
| | | |
2 | 12:35 | 2 | false |
3 | 12:35 | 5 | false |
4 | 12:35 | 9 | true |
I tried this query:
更新table1设置有效='true'when不在table1 group中的id in in dem in dim in table 1 group按时间)
>
但是它仅更新具有最大ID的行,我无法弄清楚如何用最大持续时间更新行。
谢谢。
I'm looking for an UPDATE statement where it will update a row that have duplicated timestamp and update only the row that have a MAX value at the duration column, I can utilize in Oracle SQL or PL/SQL.
Here is an example TABLE1 to work with:
ID | TIME | DURARTION | VALID |
---|---|---|---|
1 | 12:30 | 6 | - |
2 | 12:35 | 2 | - |
3 | 12:35 | 5 | - |
4 | 12:35 | 9 | - |
Result expected:
ID | TIME | DURARTION | VALID |
---|---|---|---|
1 | 12:30 | 6 | TRUE |
2 | 12:35 | 2 | FALSE |
3 | 12:35 | 5 | FALSE |
4 | 12:35 | 9 | TRUE |
I tried this query:
update TABLE1 set VALID = 'TRUE' where id not in (select max(id) from TABLE1 group by TIME)
but it update only the row with the max ID, I couldn't figure figure out how to update the row with the max DURATION.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用案例子句以true或false更新值。
You can use case clause to update value with TRUE or FALSE.
Here is a small demo that I hope it will help