Oracle SQL-以最大值更新重复

发布于 2025-01-26 06:42:36 字数 1041 浏览 4 评论 0原文

我正在寻找一个更新语句,它将更新具有重复时间戳的行,并仅更新在“持续时间”列处最大值的行,我可以在Oracle SQL或PL/SQL中使用。

使用

示例1可以
一个

Result expected:
212:352false
312:355false
412:359true

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:

IDTIMEDURARTIONVALID
112:306-
212:352-
312:355-
412:359-

Result expected:

IDTIMEDURARTIONVALID
112:306TRUE
212:352FALSE
312:355FALSE
412:359TRUE

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空宴 2025-02-02 06:42:36

您可以使用案例子句以true或false更新值。

update TABLE1
set tru_false = case when (TIME, duration) in (select time, max(duration) from TABLE1 group by time)
                then 'TRUE'
                else 'FALSE'
                END

You can use case clause to update value with TRUE or FALSE.

update TABLE1
set tru_false = case when (TIME, duration) in (select time, max(duration) from TABLE1 group by time)
                then 'TRUE'
                else 'FALSE'
                END

Here is a small demo that I hope it will help

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文