Oracle(第四天)

1、去重distinct
語法格式:select distinct 列名稱 from 表名稱
2、統計函數
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
3、
一、分組查詢(關鍵字):group by
二、篩選過濾(關鍵字):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;
三、排序 order by
  1)、order by子句在整個select語句中的位置始終位於最後。
  2)、asc表升序,通常默認與省略,desc表降序。
  3)、空值是最大的。
  4)、其後可跟多列,依次對列進行排序。
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;
 
5、練習題:
 
 
外鏈接練習題:
 

上面練習用到的四個表。
相關文章
相關標籤/搜索