首页 > 数据库技术 > 详细

码字定式之SQL(5)

时间:2014-11-27 12:23:14      阅读:152      评论:0      收藏:0      [点我收藏+]
  1. --等值连接
  2. select dname, loc, empno, ename from emp a, dept b where a.deptno=b.deptno and b.deptno=20;
  3. --自连接
  4. select a.empno, a.sal, b.empno, b.ename, b.sal from emp a, emp b where a.mgr=b.empno and a.ename=‘SCOTT‘;
  5. --笛卡尔积
  6. select a||‘+‘||b||‘=‘||(a+b) as "3*3加法表" from (select rownum a from all_objects where rownum<4), (select rownum b from all_objects where rownum<4);
  7. --内连接
  8. select empno, ename, sal, salgrade.grade from emp, salgrade where emp.deptno=10 and emp.sal between salgrade.losal and salgrade.hisal;
  9. select empno, ename, sal, salgrade.grade from emp inner join salgrade on emp.deptno=10 and emp.sal between salgrade.losal and salgrade.hisal;
  10. --反连接
  11. select * from emp where deptno not in (select deptno from dept where loc in(‘NEW YORK‘, ‘DALLAS‘));
  12. select * from dept where deptno not in (select deptno from emp);
  13. --半连接
  14. select * from emp a where exists (select 1 from dept b where loc=‘NEW YORK‘ and a.deptno=b.deptno);
  15. select a.* from emp a, dept b where loc=‘NEW YORK‘ and a.deptno=b.deptno;
  16. select * from dept a where exists (select 1 from emp b where a.deptno=b.deptno and b.sal>2900);
  17. select a.* from dept a , emp b where a.deptno=b.deptno and b.sal>2900;
  18. select distinct a.* from dept a , emp b where a.deptno=b.deptno and b.sal>2900;






码字定式之SQL(5)

原文:http://www.cnblogs.com/mahun/p/4126067.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!