使用另一个查询的结果更新 postgres 字段
我有以下格式的表格。
Moderations table
+---------+------------+--------------+
| mod_id | post_id | is_moderated |
+---------+------------+--------------+
| 1 | 1 | true |
+---------+------------+--------------+
| 2 | 2 | false |
+---------+------------+--------------+
| 1 | 3 | false |
+---------+------------+--------------+
| 3 | 4 | false |
+---------+------------+--------------+
| 4 | 5 | false |
+---------+------------+--------------+
我有另一个表来跟踪特定模块是否处于活动状态。
Moderator Table
+---------+---------------+
| mod_id | is_mod_active |
+---------+---------------+
| 1 | true |
+---------+---------------+
| 2 | false |
+---------+---------------+
| 3 | false |
+---------+---------------+
| 4 | true |
+---------+---------------+
我执行以下查询来获取未经审核的审核请求,以及分配的审核者已变为非活动状态的审核请求。
SELECT *
from
moderation
left join moderator
on mod_id=user_id
where
is_mod_active = false and
is_moderated = false
order by
created_on
对于这些选定的行,我想使用以下查询更新 mod_id 字段
SELECT mod_id
FROM
moderator
WHERE
is_mod_active = true
第二个查询将比第一个查询更短或更长。有办法更新这个吗?
I have table with following format.
Moderations table
+---------+------------+--------------+
| mod_id | post_id | is_moderated |
+---------+------------+--------------+
| 1 | 1 | true |
+---------+------------+--------------+
| 2 | 2 | false |
+---------+------------+--------------+
| 1 | 3 | false |
+---------+------------+--------------+
| 3 | 4 | false |
+---------+------------+--------------+
| 4 | 5 | false |
+---------+------------+--------------+
I have another table that tracks whether a particular mod is active.
Moderator Table
+---------+---------------+
| mod_id | is_mod_active |
+---------+---------------+
| 1 | true |
+---------+---------------+
| 2 | false |
+---------+---------------+
| 3 | false |
+---------+---------------+
| 4 | true |
+---------+---------------+
I perform following query to get the moderation requests that are unmoderated, and for whom assigned moderator has gone inactive.
SELECT *
from
moderation
left join moderator
on mod_id=user_id
where
is_mod_active = false and
is_moderated = false
order by
created_on
for these selected rows I would like to update the mod_id field with following query
SELECT mod_id
FROM
moderator
WHERE
is_mod_active = true
The second query will be shorter or longer than the first query. Is there a way to update this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论