现有表 no su a 1 a 3 a -2 a -2 b 1 b -3 b 1 orcal用sql如何得到 no su a 4 a -4 b 2 b -3
时间: 2024-11-29 20:35:14 浏览: 16
看起来您想要用SQL查询将现有的"no"和"su"值从两个表"a"和"b"合并,并添加新的值到指定的行。但是提供的信息不完整,因为没有具体的表名和列名。不过我可以给出一个假设的示例,如果您的表名为`table_a`和`table_b`,并且需要更新的是`no`和`suspected_value`两列,您可以尝试这样的查询:
```sql
UPDATE table_a
SET suspected_value = COALESCE(suspected_value, a_column)
FROM (SELECT 'a' as type, 4 as value UNION ALL SELECT 'a', -4 FROM dual UNION ALL SELECT 'b', 2 FROM dual UNION ALL SELECT 'b', -3 FROM dual) AS new_values
WHERE table_a.no = new_values.type AND table_a.suspected_value IS NULL;
UPDATE table_b
SET suspected_value = COALESCE(suspected_value, b_column)
FROM (SELECT 'a' as type, 4 as value UNION ALL SELECT 'a', -4 FROM dual UNION ALL SELECT 'b', 2 FROM dual UNION ALL SELECT 'b', -3 FROM dual) AS new_values
WHERE table_b.no = new_values.type AND table_b.suspected_value IS NULL;
```
这里,`a_column`和`b_column`应该替换为您实际表中对应的列名。这个查询会检查`table_a`和`table_b`中`suspected_value`为空的行,并将其与新的值匹配并更新。
请注意,这只是一个示例,实际操作前请根据您的数据库结构调整。
阅读全文