数据的查询
加载部门数据

部门表,第一字段代表部门编号,第二个字段代表部门名称,第三个字段代表部门人数。
create table table_4_dept_select( deptNo int, deptName String, deptCount int ) row format delimited fields terminated by '\t' lines terminated by '\n';加载数据
load data local inpath '/opt/data/hive/hive_4_dept.txt' into table table_4_dept_select;
加载员工数据

员工数据
字段分别为 员工ID,员工姓名,职业名称,部门代码,出生日期,工资,工作天数,性别,家庭地址,联系方式,技能。
create table table_4_people_select( empNo int, empName String, empNickName String, empDepCode int, empBirth String, empWages double, empWorkDay int, empGender int, empAddress struct<prov:string,cite:string,area:string>, empContact map<string,string>, empSkilled array<string> ) row format delimited fields terminated by ',' collection items terminated by '-' map keys terminated by ':' lines terminated by '\n';加载数据
load data local inpath '/opt/data/hive_4_emp.csv' into table table_4_people_select;
1 select … from语句
1.查询所有
select * from table_name;
# 查询所有员工的所有信息
select * from table_4_people_select;
2.查询指定的字段
查询基本数据类型的字段
select 字段名,字段名,... from table_name;
#查询所有员工的名字,职业
select empName,empNickName from table_4_people_select;
查询array类型的的字段
select 字段名[index] from table_name;
#查询所有员工的所有爱好,第一项爱好,第五项爱好
select empSkilled, empSkilled[0] ,empSkilled[4]from table_4_people_select;
字段是数组的名字,则显示数组中所有的值,
如果想显示array中的第几个元素,则加上下标,如果没有值显示null。
查询map类型的字段
select 字段[k] from table_name;
#查询对应map字段的所有值,查询指定map的key的值
select empContact, empContact['tel'] ,empContact['qq']from table_4_people_select;
查询struct类型的字段
select 字段.key from table_name;
#查询struct字段内所有的值,查询struct中某个属性的值
select empAddress, empAddress.</

本文详细介绍了Hive数据查询,包括select...from语句的各种用法,如查询所有、指定字段、列别名、算术表达式和常用函数。还涉及了where语句的比较和逻辑运算符,以及Group By、Having语句在分组统计中的作用。此外,还讨论了Order By的全局排序和内排序,以及CASE关键字在条件分支中的应用。
最低0.47元/天 解锁文章
795

被折叠的 条评论
为什么被折叠?



