hive数据库的一些应用

1、创建表格create table usr_info(mob string,reason string,tag string) row format delimited fields terminated by '\t' stored as textfile;
2、将本地文件上传到创建表格中load data local inpath'/home/one.txt' overwrite into table usr_info;
3、修改表格中某个列的属性或列名alter table usr_info change mob mobile int;
4、删除表格drop table usr_info;
5、
  表名aaa
  id
  1
  2
  3
  表名bbb
  id
  1
  2
  4
left join 左关联(向左对齐,右边表格没有的为null)
例(
select 
  aaa.* 
  ,bbb.* 
from 
  aaa 
left join 
  bbb 
on(aaa.id=bbb.id)

)
得到
  1 1
  2 2
  3 null
right join 右关联(向右对齐,左边表格没有的为null)
得到
  1 1
  2 2
  null 4
full join 全关联
得到
  1 1
  2 2
  3 null
  null 4
join 内关联
得到
  1 1
  2 2
6、desc 降序,asc升序
7、举例

hive -e"
select 
pt
,min(amt) as min_money
,max(amt) as max_money
,count(distinct amt) as money_cnt
,sum(amt) as sum_money
from 
usr_pay
where pt<='2015-09-14' and pt>='2015-09-13'
group by pt
having min(amt)>10
order by pt desc"

8、 表格a union all b
要求列数、列名、列的顺序必须一致,最后得到的是结果的简单罗列(不去重)
9、order by rand()将前面得到的结果随机排序

10、if(one,two,three)用法 含义为如果one是真,取two,否则取three

11、case when one then two when three then four else five end as tag 用法含义同上

12、nvl(mob,1)用法 含义为如果mob是空,将它置为1

posted @ 2015-09-16 13:54  白鹭倾城  阅读(400)  评论(0编辑  收藏  举报