【发布时间】:2018-08-04 14:16:22
【问题描述】:
我试图弄清楚如何从另一个表中更新一个表,这是 PL/SQL 中查询的结果。
这是我尝试做的:
update c
set c.customerType = n.newType
from customers c
join
(select
c.customerNumber, c.customerType,
case when c.customerType = 'business' and count(s.subCode) = 1
then 'small business'
else null
end as NewType
from customers c
join subscribers s on c.customerNumber = s.customerNumber
group by c.customerNumber, c.customerType) n on c.customerNumber = n.customerNumber;
注意,客户表如下所示:
customerNumber customerType
------------------------------
1 business
4 business
2 private
3 private
表 n(子查询)给出以下结果:
customerNumber customerType newType
1 business null
4 business small business
3 private null
2 private null
我做错了什么?
P.S 最终我想用 newType 更新 customerType 只在它不为空的地方..
谢谢
【问题讨论】:
-
Oracle 不支持
update中的from子句,所以你的问题很不清楚。 -
那么我如何在 oracle 中做到这一点?即如何从另一个表中更新一个表,这是子查询的结果?谢谢
标签: sql join plsql sql-update