Hive HQL语法:DDL、DQL

Hive HQL语法:DDL、DQL

1、DDL
创建数据库 create database 库名;
查看数据库 show databases;
删除数据库 drop database 库名;
强制删除数据库:drop database tmp cascade;
查看表:SHOW TABLES;
查看当前表在哪个数据库 select current_database();
查看表的元信息:
    desc test_table;
    describe extended test_table;    #未格式化的元数据
    describe formatted test_table;   #格式化后的元数据
查看建表语句:show create table table_XXX
重命名表:
    alter table test_table rename to new_table;
修改列数据类型:alter table lv_test change column colxx string;
增加、删除分区:
    alter table test_table add partition (pt=xxxx) 
    alter table test_table drop if exists partition(...);

上面实际上都是对元数据进行操作,对数据本身并未操作
2、DQL
顺序:
select id,name from tb t where ... and .... group by xxx having xxxx order by xxx asc/desc limit n;
  • where :指定条件、过滤数据、分区裁剪

  • join:两表关联,left join、right join、join 注意MapJoin

    image-20210114163507425.png

  • group by :分组聚合,通常结合聚合函数一起使用

    常用聚合函数:
    求和:sum	求最大值:max	求最小值:min	求数量count	求均值avg
    保留几位小数:round	字符串拼接:concat
    
  • order by:全局排序(效率低、执行慢),对所有的reduce输出是有序的

    image-20210114163527883.png

  • sort by:局部排序,对单个reduce输出是有序的

    image-20210114163546748.png

  • distribute by:分区

    image-20210114163558443.png

  • cluster by = distribute by + sort by

image-20210114163608574.png

  • distinct:去重

https://zhuanlan.zhihu.com/p/93747613 order by、distribute by、sort by、cluster by详解

posted @   阿伟宝座  阅读(112)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示