方式一
create temporary table 临时表表名 as
select * from 表名;
hive中的临时表只对当前session有效,session退出后,表会自动删除
注:
若创建的临时表表名已经存在,那么当前session应用该表名时使用的是你创建的临时表,只有删除或者修改临时表才能使用原先存在的表。
临时表不支持分区字段和创建索引
方式二with a1 as (select * from A) select * from a1;
1.with as 属于一次性的,后面必须加其他sql一起使用才可以!不然会报错!
2.这里必须要整体作为一条sql查询,即with as语句后不能加分号,不然会报错
多个with as 的使用
with a1 as (select * from A), a2 as (select * from a1) select * from a2;
1.多个with as 使用必须使用逗号隔开,
2.前面with as生成的临时表可以在后面的with as中使用 但是with子句内部不能嵌套with子句



