建库db203
1. create database db203; 2. create database if not exists db203; 3. use db203;
根据city数据的格式建表city
1. create table if not exists city 2. (id int, 3. name string) 4. row format delimited fields terminated by '\t';
把数据加载到表中
1. load data inpath '\data\city.txt' overwrite into table city; 2. select * from city;
根据salary数据的格式建表salary
1. create table if not exists salary 2. (id int, 3. income int) 4. row format delimited fields terminated by ',';
把数据加载到表中
load data inpath '\data\salary.txt' overwrite into table salary;
关联查询表city和表salary,得到城市名称和收入,将输出安装收入倒叙排序
select * from city join salary on city.id=salary.id
将输出以文件格式存储到hdfs中
1. insert overwrite directory '/data/result' 2. row format delimited fields terminated by ':' 3. select a.name,b.income from city a join salary b on a.id=b.id 4. order by b.income desc;