【发布时间】:2021-05-17 21:50:43
【问题描述】:
| id | userid | deviceid | isactive | last_modified (timestamp) |
|---|---|---|---|---|
| 1 | 12 | fdghfgh | true | 2021-02-12 |
| 2 | 12 | sdsdfg | true | 2021-02-14 |
| 3 | 5 | fghfgh | true | 2021-01-12 |
| 4 | 15 | dffdg | true | 2021-02-14 |
| 5 | 15 | dofghfjdog | true | 2021-01-09 |
一个用户只能使用一台设备。上表用户 12 和 15 拥有两个活动设备。
如何在postgresql查询中将最近修改的设备设置为active,其他设备设置为false(对应用户)?
结果应该是:
| id | userid | deviceid | isactive | last_modified (timestamp) |
|---|---|---|---|---|
| 1 | 12 | fdghfgh | false | 2021-02-12 |
| 2 | 12 | sdsdfg | true | 2021-02-14 |
| 3 | 5 | fghfgh | true | 2021-01-12 |
| 4 | 15 | dffdg | true | 2021-02-14 |
| 5 | 15 | dofghfjdog | false | 2021-01-09 |
【问题讨论】:
-
到目前为止您有什么疑问?你为什么不只是edit your original question
标签: sql postgresql duplicates sql-update