最近一段时间因工作需要接触了一些hive上的使用!当然大部分都是比较基本的使用,仅当入门!各位看到有不足之处望多多指正!

废话不多说,开始:

首先是创建数据库

create database ‘数据库名称’

创建外部表(大部分时候我使用的是外部表):

CREATE EXTERNAL TABLE tmp.lng_lat(
lng string,
lat string)
ROW FORMAT SERDE
'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
WITH SERDEPROPERTIES (
'field.delim'=',',
'line.delim'='\n',
'serialization.format'=',')
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
'/user/guojienan/tmp/tmp1/lng_lat'

注意 “ ' ” 并不是引号  是键盘左上角的 “ ~ ” 号!

LOCATION
'/user/guojienan/tmp/tmp1/lng_lat'
是指外表存放路径!
 
停用临时表
drop table 数据库名称.表名
查看建表语句:
show create table
插入数据:
向外表插入数据
insert into table tmp.tmp_xiaoqutong
SELECT(查询语句) from
直接数据插入分区
INSERT INTO TABLE test_olap_event PARTITION (date='2018-01-19',hour='02') values('1',88888888,7777777)
覆盖插入
INSERT OVERWRITE TABLE test_olap_event PARTITION (date='2018-01-19',hour='02') values('1',88888888,7777777)
 
连接函数的一点用法
concat、concat_ws、group_concat函数用法
一、concat()函数可以连接一个或者多个字符串
  CONCAT(str1,str2,…) 返回结果为连接参数产生的字符串。如有任何一个参数为NULL ,则返回值为 NULL。
  select concat('11','22','33');     112233
二、CONCAT_WS(separator,str1,str2,...) 
  是CONCAT()的特殊形式。第一个参数是其它参数的分隔符。分隔符的位置放在要连接的两个字符串之间。分隔符可以是一个字符串,也可以是其它参数。
    select concat_ws(',','11','22','33');    11,22,33
三、group_concat()分组拼接函数
  group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator '分隔符'])
  对下面的一组数据使用 group_concat()
  | id |name
  |1 | 10|
  |1 | 20|
  |1 | 20|
  |2 | 20|
  |3 | 200   |
  |3 | 500   |
  1、select id,group_concat(name) from aa group by id;
  |1 | 10,20,20|
  |2 | 20 |
  |3 | 200,500|
  2、select id,group_concat(name separator ';') from aa group by id;
  |1 | 10;20;20 |
  |2 | 20|
  |3 | 200;500   |
  3、select id,group_concat(name order by name desc) from aa group by id;
  |1 | 20,20,10   |
  |2 | 20|
  |3 | 500,200|
  4、select id,group_concat(distinct name) from aa group by id;
  |1 | 10,20|
  |2 | 20   |
  |3 | 200,500 |
 
 
 
 
 

最新文章

  1. PHP Object 转 Array,Json 转 Array
  2. php查找字符串首次出现的位置 判断字符串是否在另一个字符串中
  3. GRIDVIEW多行多列合并单元格(合并列)
  4. 泰泽新闻:英特尔三星双否认泰泽Tizen系统已死
  5. iOS的扩展类,扩展属性
  6. 针对ie9写特殊的样式
  7. poj 1742 多重背包
  8. Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)ABCD
  9. git(windows)
  10. 【从零开始自制CPU之学习篇04】电容
  11. 方差分析 | ANOVA | 原理 | R代码 | 进阶 | one way and two way
  12. Spring Boot 启动(二) 配置详解
  13. mongoose的save无效的问题
  14. #SQL1242错误
  15. Confluence 6 缓存性能优化
  16. ElementLayer support not implemented for native rendering. Layer ID:
  17. 内置函数id,返回内存地址
  18. acm入门练习心得
  19. Explaining Delegates in C# - Part 7 (Asynchronous Callback - Way 4)
  20. Python进阶 学习笔记(二)

热门文章

  1. useradd 命令详解
  2. 【简单理解】gulp和webpack的区别
  3. 当你的电脑出现stop: 0X0000007B
  4. Spark 核心概念 RDD 详解
  5. animate.css – 齐全的CSS3动画库
  6. NestedScrollingParent, NestedScrollingChild 详解
  7. 面试经验And总结
  8. spring boot 之fastJson的使用(二)
  9. vue2.0 页面A跳转到页面B,B页面停留在A页面的滚动位置的解决方法
  10. C#wxpay和alipay