在PostgreSQL数据库中给出以下两个表...
表observation
:
+---------------+---------+
| observationid | deleted |
+---------------+---------+
| 1 | F |
| 2 | F |
| 3 | F |
+---------------+---------+
表numericvalue
:
+---------------+-------+
| observationid | value |
+---------------+-------+
| 1 | 999 |
| 2 | 5 |
| 3 | 999 |
+---------------+-------+
每当deleted
中的关联行包含'T'
等于observation
时,我想在numericvalue
的所有行中将列value
的值设置为999
SELECT
。
SELECT *
FROM observation o
INNER JOIN numericvalue n
ON o.observationid = n.observationid
AND n.value = 999;
查询如下所示:
import re
some_var = "what what"
should_match = "what what what what what what hey"
not_a_match = "what what what what hey what what"
match = re.search(re.escape(some_var){3}, should_match)
no_match = re.search(re.escape(some_var){3}, not_a_match)
答案 0 :(得分:1)
UPDATE observation ob
SET deleted = 'T'
FROM numericvalue nv
WHERE nv.value = 999
AND nv.observationid = ob.observationid;
答案 1 :(得分:0)
UPDATE observation
SET deleted = 'T'
WHERE observationid IN (SELECT observationid FROM numericvalue WHERE value=999)