Hive(7)-基本查询

 坐标帝都,寻坑一个

create table if not exists dept  ( deptno int, dname string, loc int ) row format  delimited  fields terminated by '\t';  create table if not exists emp (empno int, ename string, job string, mgr int, hiredate string,  sal double,  comm double, deptno int ) row format  delimited fields terminated by '\t';  create table if not exists location ( loc int, loc_name string ) row format  delimited fields terminated by '\t';  create table if not exists student ( id int, name string ) row format  delimited fields terminated by '\t';
复制代码

3. 上传数据到/opt/datas目录下,使用jdbc连接hive,导入表数据

复制代码
load data local inpath '/opt/datas/dept.txt' into table dept;  load data local inpath '/opt/datas/emp.txt' into table emp;  load data local inpath '/opt/datas/location.txt' into table location;  load data local inpath '/opt/datas/student.txt' into table student;
复制代码

 

二. 基本查询(select...from...)

1. 全表和指定列查询

复制代码
-- 全表查询select * from emp;  -- 指定列查询select empno, ename from emp;
复制代码

注意: 

1). SQL语言大小写不敏感

2). SQL可以写在一行或多行

3). 关键字不能被缩写,也不能分行

4). 各子句一般分行写

5). 使用缩进提高语句的可读性

2. 列别名

复制代码
-- 重命名一个列 -- 便于计算 -- 紧跟列名,也可以在列名和别名之间加入关键字 asselect ename name, deptno dn from emp;
50000+
5万行代码练就真实本领
17年
创办于2008年老牌培训机构
1000+
合作企业
98%
就业率

联系我们

电话咨询

0532-85025005

扫码添加微信