hive中一些常用的sql语句

时间:2023-08-14 18:58:02

1.建表

CREATE TABLE IF NOT EXISTS student(
time varchar(64) ,
num int ,
age int
)
PARTITIONED BY ( score int)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
STORED AS PARQUET tblproperties("parquet.compress"="SNAPPY");

2.加载数据

load data local inpath '/opt/datas/student.txt' overwrite into table student ;

3.删除表

DROP table database_name.table_name;

4.修改表的字段名

ALTER TABLE student CHANGE age height int

5.截断表(即清空表的数据)

truncate student

6.一些查询语句

1.select * from student order by age ;

2.select * from student sort by age ;

3.select * from student group by age;

4.select * from student group by age having num > 100;

5.select * from student where age>13;

6.select s1.name, s1.age, s2.name, s2.money from student1 s1 join student2 s2 on s1.name=s2.name ;

7.select * from student1 order by age limit 3 union select * from student2 order by age limit 3;

8.select distinct age from student