
#### 15. 为表emp\_hr3删除列salary
alter table emp_hr3 replace columns(
name string,
employee_ids string,
sin_number string,
start_date date,
sex string,
age int
);

#### 16. 创建一个新表emp\_hr2,并从已经存在的emp\_hr1表中插入数据name,start\_date,sex和age 到新表emp\_hr2
create table emp_hr2(
name string,
start_date date,
sex string,
age int
);

insert into emp_hr2 select name,start_date,sex,age from emp_hr1;

简单方法:
create table emp_hr2 as select name,start_date,sex,age from emp_hr1;
#### 17. 创建新表emp\_hr4,包含字段name(名字,字符串), start\_date(入职时间,date), sex(性别,字符串),age(年龄,整形)每个字段之间由[ | ]分割,从emp\_hr2中向emp\_hr4表中插入数据。
–创建新表emp_hr4
create table emp_hr4(
name string,
start_date date,
sex string,
age int
)
row format delimited fields terminated by ‘|’;
–插入数据
insert into emp_hr4 select name,start_date,sex,age from emp_hr2;

#### 18. 求emp\_hr2的总行数(count)
select count(*) cnt from emp_hr2;

#### 19. 求emp\_hr2中年龄最大值和最小的值
select max(age) max_age from emp_hr2;
select min(age) min_age from emp_hr2;


#### 20. 求emp\_hr2中年龄的平均值
select avg(age) avg_age from emp_hr2;

#### 21. 查询emp\_hr2的前5行的名字和年龄
select name,age from emp_hr2 limit 5;

#### 22. 查询出年龄大于50的所有员工名字与年龄
select name,age from emp_hr2 where age>50;

#### 23. 查询出年龄介于20到30之间的所有员工名字与年龄
select name,age from emp_hr2 where age between 20 and 30;

#### 24. 查询出到退休年龄55岁的所有员工名字与年龄
select name,age from emp_hr2 where age=55;

#### 25. 查询出年龄在25到55岁以外的所有员工名字与年龄
select name,age from emp_hr2 where age not between 20 and 55;

#### 26. 查找年龄以5开头的员工姓名和性别信息
select name,sex from emp_hr2 where age like ‘5%’;

#### 27. 查找年龄第二位为2的员工姓名和性别信息
select name,sex from emp_hr2 where age like ‘_2’;

#### 28. 在emp\_hr2中查询年龄大于40且性别是male的员工信息
select * from emp_hr2 where age>40 and sex=‘male’;

#### 29. 在emp\_hr2中查询性别除了male以外的员工信息
select * from emp_hr2 where sex!=‘male’;
–或者
select * from emp_hr2 where sex=‘female’;

#### 30. 计算emp\_hr2表平均年龄按照男女分组
select avg(age), sex from emp_hr2 group by sex;

#### 31. 计算emp\_hr2表男女的最高,最低年龄
select max(age) max_age,min(age) min_age, sex from emp_hr2 group by sex;

#### 32. 计算emp\_hr2表平均年龄大于34的性别
select sex from emp_hr2 group by sex having avg(age)>34;

#### 33. 查询emp\_hr2表中姓名,按照员工离退休年龄55岁的相差岁数,降序排序。(大于55岁的为返聘人员不计入排序)
select name,(55-age) new_age from emp_hr2 where age=<55 order by new_age desc;

注:返回数据过多,仅截取了部分数据。
#### 34. 查询emp\_hr2表中姓名,性别,年龄,按照性别进行分区,年龄升序排序。
select name, sex, age from emp_hr2 distribute by sex sort by age;

注:返回数据过多,仅截取了部分数据。
#### 35. 在数据库empdb下新建分区表emp\_hr1\_part1, 分别包含字段name(名字,字符串),employee\_id(id,字符串),sin\_number(电话,字符串),start\_date(入职时间,date),age(年龄,整形),以sex\_m(性别,字符串)来分区,每个字段之间由[ | ]分割.
create table emp_hr1_part1(
name string,
employee_id string,
sin_number string,
start_date date,
sex string,
age int
)
partitioned by (sex_m string)
row format delimited fields terminated by ‘|’;

#### 36. 从emp\_hr1中将name, employee\_id, sin\_number, start\_date, age和sex=’male’的数据插入到分区表emp\_hr1\_part1的分区sex\_m=‘male’中。
–打开动态分区
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
insert into emp_hr1_part1 partition(sex_m=‘male’)
select * from emp_hr1 where sex=‘male’;

#### 37. 为表emp\_hr1\_part1增加分区sex\_m=’female’
alter table emp_hr1_part1 add partition(sex_m=‘female’);

#### 38. 从emp\_hr1中将name, employee\_id, sin\_number, start\_date, age和sex=’female’的数据插入到分区表emp\_hr1\_par1的分区sex\_m=‘female’中。
insert into emp_hr1_part1 partition(sex_m=‘female’)
select * from emp_hr1 where sex=‘female’;
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
_hr1 where sex=‘female’;
[外链图片转存中…(img-stblefuc-1714761210297)]
[外链图片转存中…(img-adwwfq1w-1714761210297)]
[外链图片转存中…(img-zgmat012-1714761210298)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
发表评论