Hive基本查询操作
1、前提条件
1.1、创建表
在hive中创建一张表
1.2、加载数据
将本地模式下opt下的表格加载到hive中
2.1 全表和特定列查询
1)全表查询
2)选择特定列查询
注意:
(1)SQL 语言大小写不敏感。
(2)SQL 可以写在一行或者多行
(3)关键字不能被缩写也不能分行
(4)各子句一般要分行写。
(5)使用缩进提高语句的可读性
2.2 列别名
(1)查询名称和部门
2.3 算术运算符
(1)A+B
(2)A-B
(3)A*B
(4)A/B
(5)A%B
(6)A&B
(7)A|B
(8)A^B
(9)~A
2.4常用函数
若运行函数命令出错解决办法:
https://blog.****.net/weixin_45618366/article/details/106476781
1)求总行数(count)
命令: select count(*) cnt from emp;
2)求工资的最大值(max)
select max(sal) max_sal from emp;
3)求工资的最小值(min)
select min(sal) min_sal from emp;
4)求工资的总和(sum)
select sum(sal) sum_sal from emp;
5)求工资的平均值(avg)
select avg(sal) avg_sal from emp;
2.5 Limit 语句
典型的查询会返回多行数据。LIMIT 子句用于限制返回的行数。
select * from emp limit 5;