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
-
group by :分组聚合,通常结合聚合函数一起使用
常用聚合函数: 求和:sum 求最大值:max 求最小值:min 求数量count 求均值avg 保留几位小数:round 字符串拼接:concat
-
order by:全局排序(效率低、执行慢),对所有的reduce输出是有序的
-
sort by:局部排序,对单个reduce输出是有序的
-
distribute by:分区
-
cluster by = distribute by + sort by
- distinct:去重
https://zhuanlan.zhihu.com/p/93747613 order by、distribute by、sort by、cluster by详解
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!