zoukankan      html  css  js  c++  java
  • hive数据库的一些应用

    1、创建表格create table usr_info(mob string,reason string,tag string) row format delimited fields terminated by ' ' 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

  • 相关阅读:
    做了一些心理学的测试,分析下个人
    做了一些心理学的测试,分析下个人
    逆转一个整数
    打印九九乘法表
    计算两个日期相差多少天
    struct的使用
    Linux Vim替换字符串的一些方法小结
    CentOS里vim基本操作
    如何创建一个后台进程
    高中是个把人分类的机器(转)
  • 原文地址:https://www.cnblogs.com/dudumiaomiao/p/4813141.html
Copyright © 2011-2022 走看看