乐趣区

关于sql:create-table-as-与create-table-like

相同点:

都是创立一个新表

不同点
  • create table as 只是复制原数据,其实就是把查问的后果建一个表
  • create table like 产生与源表雷同的表构造,包含索引和主键,数据须要用 insert into 语句复制进去。

举例:
`
DROP TABLE IF EXISTS l_medicine.user_tmp;

CREATE TABLE l_medicine.user_tmp LIKE l_medicine.user;

INSERT INTO l_medicine.user_tmp PARTITION (platform_id)

SELECT

u.created_at,

u.updated_at,

CASE WHEN n.user_id IS NULL THEN 0 ELSE 1 END AS noise,

u.platform_id

FROM l_medicine.user AS u

LEFT JOIN transforms.medicine_inquiry_user_noise AS n

ON u.user_id = n.user_id;
`

退出移动版