一、去重distinct
语法格式:select distinct 列名称 from 表名称
二、统计函数
avg(x)
count(1) count(*)
max(x)
min(x)
sum(x)
stddev(x) 求一组行中列x值的标准差
variance(x) 求一组行中列x值的方差
round与trunc:
select round(avg(sal),4) from emp; 四舍五入,取整
select trunc(avg(sal),4) from emp; 不管小数点精确位数的后一位有多大都不进1
三、
1、分组查询(关键字):group by
2、筛选过滤(关键字):having
  select deptno,max(sal) from emp group by deptno;
  当使用分组语句时,在select语句中出现的列,一定要在group by中出现
  select deptno job,avg(sal) from emp group by deptno,job;
  having语句 有having语句一定有group by语句,反之不一定。
  select deptno ,avg(sal) from emp group by deptno having avg(sal)>2000;
3、排序 order by
  1)、order by子句在整个select语句中的位置始终位于最后。
  2)、asc表升序,一般默认与省略,desc表降序。
  3)、空值是最大的。
  4)、其后可跟多列,依次对列进行排序。
四、连接查询
1.内连接:显式内连接(inner join on)、隐式内连接(where and )
2.外连接:左外连接(left join)、右外连接(right join)、完整外连接(full join)
 
 
  select e. *,dname ,loc from emp e
  full join dept d on e.deptno =d.deptno
  where e.deptno = 10;
 
五、练习题:
 
 
外连接练习题:
 

上面练习用到的四个表。
 

posted on 2020-11-13 23:15  史振兴  阅读(162)  评论(0编辑  收藏  举报