左连接:
select * from a left join b on a.id=b.id;
创建分区表(external)
create external table if not exists testdemo
(id int comment ‘id’,name string comment ‘name’ ,salary double comment ‘salary’)
partitioned by (age int comment ‘age’)
row format delimited fields terminated by ‘,’
stored as textfile;
分区表中分别导入数据(/user/hive/warehouse/bd1811.db/testdemo/age=19,20 2个文件夹)
load data inpath ‘/data/dowun20.txt’ overwrite into table testdemo partition (age=19);
load data inpath ‘/data/up20.txt’ overwrite into table testdemo partition (age=21);
查询分区内容
select * from testdemo where age=21;
查看分区内容
show partitions testdemo;
新建2个桶(/user/hive/warehouse/bd1811.db/test02 生成2个文件000000_0,000001_0)
create external table if not exists test02
(id int comment ‘id’,name string comment ‘name’ ,salary double comment ‘salary’,age int comment ‘age’)
clustered by (id) sorted by (id desc) into 2 buckets;
添加桶的数据
insert overwrite table test02 select *from testdemo;