1 insert into city values(1,'北京','彰顯大氣'); 2 insert into city values(2,'上海','繁華都市'); 3 insert into city values(3,'廣州','凸顯溫馨'); 4 insert into city values(4,'深圳','年輕氣氛'); 5 insert into city values(5,'北上廣深','不相信眼淚'); 6 commit; 7 update dept set loc='1' where deptno=70; 8 update dept set loc='2' where deptno=10; 9 update dept set loc='3' where deptno=20; 10 update dept set loc='4' where deptno=30; 11 update dept set loc='5' where deptno=40;
員工信息表:select * from emp;函數
員工部門表:select * from dept;spa
城市表:select * from city;
三表聯合查詢舉栗子:查詢員工信息及部門名稱及所在城市的名稱
code
1 --SQL92:查詢員工信息及部門名稱及所在城市的名稱而且工資大於2000或者有獎金的 2 select e.*,d.dname,c.cname 3 from emp e,dept d,city c 4 where (e.deptno=d.deptno and d.loc=c.cid and e.sal>2000)or(e.deptno=d.deptno and d.loc=c.cid and comm is not null) 5 order by e.sal; 6 --SQL99:查詢員工信息及部門名稱及所在城市的名稱而且工資大於2000或者有獎金的 7 select e.*,d.dname,c.cname 8 from emp e 9 inner join dept d 10 on e.deptno=d.deptno 11 inner join city c 12 on d.loc=c.cid 13 where e.sal>2000 or e.comm is not null 14 order by e.sal;
重點重點重點!!!blog
--SQL92: --特色:易於書寫,難於閱讀 --缺點:92SQL語句結構不清晰。 --用法: --select 內容(別名,鏈接符,Oracle函數等) --from 表名1,表名2,表名3... --where 條件(鏈接條件,普通篩選條件,where子句關鍵字) --group by 分組字段 --having 多行函數篩選 --order by 排序字段 --SQL99 --特色:難於書寫,易於閱讀。 --用法: --select 內容 --from 表名1 --inner join 表名2 --on 鏈接條件 --inner join 表名3 --on 鏈接條件 --where 條件(鏈接條件,普通篩選條件,where子句關鍵字) --group by 分組字段 --having 多行函數篩選 --order by 排序字段