INSERT ALL
WHEN sum_orders < 10000 THEN INTO small_customers
WHEN sum_orders >= 10000 AND sum_orders < 100000 THEN INTO medium_customers
ELSE INTO large_customers
SELECT customer_id,sum(order_total) sum_orders
FROM oe.orders
GROUP BY customer_id;
需要注意上面,当指定了ALL
字句的时候,这个语句就执行无条件的多表插入。也就意味着每一个WHEN
字句按照子查询所返回的每一行来确定值而不管前一个条件的输出结果是什么,因此,在插入medium_customers的条件中,要有sum_order>10000
的条件。
INSERT ALL
INTO t1
INTO t2
SELECT *
FROM t;
网友评论