1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| - 创建数据库 create database name; - 创建数据库表( 需要先进入一个数据库 use name ) create table name (id Int, name String) row format delimited FIELDS TERMINATED BY '分隔符'; - 导入数据 ( 加上 overwrite 就会将表清空后倒入,不加上就直接导入 ) 1. 从本地导入 load data local inpath '数据地址' overwrite into table tableName; 2. hdfs上导入 load data inpath '数据地址' overwrite into tableName; - 查询 group by 分组 order by 排序 (desc倒序) group by 之后 where 要使用 having hive 中的不等于为 <> - 将查询的数据保存到其他位置 ( 加上 overwrite 就会将表清空后倒入,不加上就直接导入 ) 1. 保存到已存在的表中 insert overwrite table 保存数据的表 select * form 查询数据的表 2. 保存到未存在的表中 create table 新表名(字段名,类型) as select * from 查询数据的表 3. 保存到hdfs上 - hive 中字符串处理 博客地址( https://my.oschina.net/u/2441766/blog/1648467 ) length(字段名) 返回字段的长度 reverse(字段名) 返回反转之后的字段 concat(字段A,字段B) 返回字段A+字段B的字段 concat_ws("分隔号",字段A,字段B) 返回字段A+分隔号+字段B - hive 连接表 -join 1.left join 2.right join 3. - 建表 1. 建立普通表 create table tableName() row format delimited fields termanited by ','; 2. 建立分区表 create table tableName() pratitionted by (分区字段 字段类型) row format delimited fields termanited by ','; - 建立静态分区 alter table tableName add partition(分区字段=""); - 删除分区 alter table tableName drop partition(分区字段=""); - 删除表之前要将所有的分区都删除
|