基本的查询
查询全表及特定字段
select * from student;
select id ,name from student;
列的别名
select
deptno,
avg(sal) sal_avg
from emp
group by deptno
表的别名
提高查询效效率
select
t.id,
t.name,
b.age,
b.id
from table01 t
join table02 b
on t.id = b.id;
算数运算符
select ename, sal, comm, nvl(comm,0) +sal income from emp;
逻辑运算符
AND
select * from emp where sal > 1000 and deptno =30;
OR
select * from emp where sal >1000 or deptno=30;
NOT
select * from emp where deptno is not in(20 , 30);
常用函数
count(*)
max()
min()
avg()
sum()
limit 语句
select * from emp limit 5;
select * from emp limit 2, 3;
where 语句
查询过滤的作用
select * from emp where sal >1000;
where 后不能使用列的别名
比较运算符
A<=>B
select ename, mgr, comm , mgr<=> comm from emp;
A [not] between B and C
select * from emp where sal betwenn 1000 and 5000;
is null
is not null
in(value1, value2)
select * from emp where sal in(800, 5000);
like
简单的正则表达式,通配符模式
select ename from emp enam like 'A%';
rlike
完全的正则表达式--java
select ename from emp ename rlike '^A';
join
多表连接
笛卡尔积
分支主题
连接条件缺少,写了和没写一样
select ename, deptno from emp, dept;
排序
分区排序
分区排序的排序
sort by
在每个Reduce进行排序
分区内有序全局无序
单独使用,分区规则是什么,随机
分区排序的分区
distribute by
按照指定的分区字段进行分区
分区规则:分区字段.hash % num_reduce
cluster by
分区排序种分区字段和排序字段相同时,可以使用
cluster by 仅支持升序排序,不支持自定义,desc 或asc