hive 分组+排序 1、创建外部表employess41_table,表名中加上座位号 CREATE EXTERNAL TABLE IF NOT EXISTS employess01_table( staff_name STRING, staff_age INT, staff_salary FLOAT, late_deduction FLOAT, staff_dept STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' STORED AS textfile LOCATION '/hive'; 2、将下列数据使用基本插入方式插入到表中,并查看表中数据。 insert into table employess41_table values ("Lilith Hardy",30,6000,50,"Finance Department"), ("Byron Green",36,5000,25,"Personnel Department"), ("Yvette Ward",21,4500,15.5,""), ("Arlen Esther",28,8000,20,"Finance Department"), ("Rupert Gold",39,10000,66,"R&D Department"), ("Deborah Madge",41,6500,0,"R&D Department"), ("Tim Springhall",22,6000,36.5,"R&D Department"), ("Olga Belloc",36,5600,10,"Sales Department"), ("Bruno Wallis",43,6700,0,"Personnel Department"), ("Flora Dan",27,4000,35,"Sales Department"); 3、获取部门R&D Department中薪资大于8000的员工信息。 4、查询员工信息表employess_table的部门信息。 5、查询同一部门的工资总数。 6、查询同一部门的平均年龄。 7、执行“vi sales.txt”命令,创建商品销售额数据文件sales.txt,在数据文件sales.txt中添加如下内容。 SiChuan,ChengDu,34631 SiChuan,MianYang,54516 SiChuan,LeShan,41288 SiChuan,Deyang,13492 SiChuan,PanZhiHua,48080 SiChuan,YaAn,64473 SiChuan,DuJiangYan,12464 SiChuan,LuZhou,29712 HuBei,WuHan,16564 HuBei,YiBin,87007 HuBei,XiaoGan,59840 HuBei,JinZhou,86992 HuBei,HuangGan,12906 HuBei,XiangYang,64564 HuBei,EnShi,23074 HeBei,ShiJiaZhuang,73612 HeBei,BaoDing,68192 HeBei,TangShan,29889 HeBei,XiangTai,86107 HeBei,LangFang,70897 HeBei,ChengDe,30378 8、在本地文件系统/home目录中创建文件夹姓名缩写,例如张三创建文件夹zs,将文件上传至本地文件系统/home/zs中 9、创建内部表sales41_table,从本地系统导入文件数据,并查询表信息。字段如下: province STRING, city STRING, sales_amount FLOAT 10、查询商品销售表sales_table中销售额排名前10的省份及城市。 11、使用ORDER BY和SORT BY分别对商品销售表sales_table中不同省份内每个城市的销售额进行排序。 12、通过手动设置参数的方式将Reducer个数调整为3,使用ORDER BY和SORT BY对商品销售表sales_table中不同省份内每个城市的销售额进行排序。
时间: 2023-08-02 18:12:10 浏览: 135
3获取部门R&D Department中薪资大于8000的员工信息。
```
SELECT * FROM employess41_table WHERE staff_dept = 'R&D Department' AND staff_salary > 8000;
```
4、查询员工信息表employess_table的部门信息。
```
SELECT DISTINCT staff_dept FROM employess41_table;
```
5、查询同一部门的工资总数。
```
SELECT staff_dept, SUM(staff_salary) AS total_salary FROM employess41_table GROUP BY staff_dept;
```
6、查询同一部门的平均年龄。
```
SELECT staff_dept, AVG(staff_age) AS avg_age FROM employess41_table GROUP BY staff_dept;
```
7、执行“vi sales.txt”命令,创建商品销售额数据文件sales.txt,在数据文件sales.txt中添加如下内容。
(此处无法执行)
8、在本地文件系统/home目录中创建文件夹姓名缩写,例如张三创建文件夹zs,将文件上传至本地文件系统/home/zs中
```
mkdir ~/zs
scp sales.txt username@remote_host:~/zs/sales.txt
```
9、创建内部表sales41_table,从本地系统导入文件数据,并查询表信息。字段如下: province STRING, city STRING, sales_amount FLOAT
```
CREATE TABLE sales41_table (
province STRING,
city STRING,
sales_amount FLOAT
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';
LOAD DATA LOCAL INPATH '~/zs/sales.txt' INTO TABLE sales41_table;
SELECT * FROM sales41_table;
```
10、查询商品销售表sales_table中销售额排名前10的省份及城市。
```
SELECT province, city, sales_amount FROM sales41_table ORDER BY sales_amount DESC LIMIT 10;
```
11、使用ORDER BY和SORT BY分别对商品销售表sales_table中不同省份内每个城市的销售额进行排序。
```
-- 使用ORDER BY
SELECT province, city, sales_amount FROM sales41_table WHERE province = 'SiChuan' ORDER BY sales_amount DESC;
-- 使用SORT BY
SELECT province, city, sales_amount FROM sales41_table WHERE province = 'SiChuan' SORT BY sales_amount DESC;
```
12、通过手动设置参数的方式将Reducer个数调整为3,使用ORDER BY和SORT BY对商品销售表sales_table中不同省份内每个城市的销售额进行排序。
```
SET mapreduce.job.reduces=3;
-- 使用ORDER BY
SELECT province, city, sales_amount FROM sales41_table WHERE province = 'SiChuan' ORDER BY sales_amount DESC;
-- 使用SORT BY
SELECT province, city, sales_amount FROM sales41_table WHERE province = 'SiChuan' SORT BY sales_amount DESC;
```
阅读全文