我有以下select语句:
SELECT * FROM pgp
WHERE group_id IN (
SELECT group_id FROM pgroups
WHERE label LIKE 'Registration%'
AND label NOT LIKE '%Snom%'
)
AND pid = 12;
它会返回如下结果:
group_id | pid | value | updatev
----------+----------+-------+----------
34 | 12 | | f
11 | 12 | | t
4 | 12 | | t
13 | 12 | | t
17 | 12 | | f
19 | 12 | | f
对于返回的所有记录,我想强制" updatev"要设置为true的字段。我不知道该怎么做。 感谢
答案 0 :(得分:1)
只需将SELECT
更改为UPDATE
:
UPDATE pgp
SET updatev = 't'
WHERE group_id IN (SELECT group_id FROM pgroups WHERE label like 'Registration%' and label not like '%Snom%') and pid = 12;
这实际上是一种很好的做法 - 在实际更改任何数据之前,使用SELECT
来确定您的标准。
答案 1 :(得分:0)
使用update
声明:
UPDATE pgp
SET updatev = true
WHERE group_id IN (SELECT group_id
FROM pgroups
WHERE label LIKE 'Registration%' AND
label NOT LIKE '%Snom%') AND
pid = 12;
答案 2 :(得分:0)
可能会工作
Update pgp
set updatev='t'
WHERE group_id IN (SELECT group_id FROM pgroups WHERE label like 'Registration%' and label not like '%Snom%') and pid = 12;