多表插入

insert all

when sum_orders  < 1000 then 

into small customers

when sum_orders >= 1000 and sum_orders <1000 then 

into mediums_customers

else

into large_customers

select customer_id,sum(order_total) sum_orders

from oe.ordrers

group by customer_id;

注意insert 关键字后面all子句的使用。当指定了ALL子句的实话,这个语句就会执行无条件的多表插入。

也就意味着每一个when子句按照子查询所返回的每一行来确定值而不管前一个条件的输出结果是什么。

因此,你需要注意如何来指定每个条件。例外,如果我使用when sum_orders < 1000这个条件而不

是像上面一样列出范围,插入medium_customers表中的行有可能也会插入small_customers表中。

原文地址:https://www.cnblogs.com/kenwong/p/4062065.html