首页 > 代码库 > 码字定式之SQL(5)
码字定式之SQL(5)
--等值连接
select dname, loc, empno, ename from emp a, dept b where a.deptno=b.deptno and b.deptno=20;
--自连接
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‘;
--笛卡尔积
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);
--内连接
select empno, ename, sal, salgrade.grade from emp, salgrade where emp.deptno=10 and emp.sal between salgrade.losal and salgrade.hisal;
select empno, ename, sal, salgrade.grade from emp inner join salgrade on emp.deptno=10 and emp.sal between salgrade.losal and salgrade.hisal;
--反连接
select * from emp where deptno not in (select deptno from dept where loc in(‘NEW YORK‘, ‘DALLAS‘));
select * from dept where deptno not in (select deptno from emp);
--半连接
select * from emp a where exists (select 1 from dept b where loc=‘NEW YORK‘ and a.deptno=b.deptno);
select a.* from emp a, dept b where loc=‘NEW YORK‘ and a.deptno=b.deptno;
select * from dept a where exists (select 1 from emp b where a.deptno=b.deptno and b.sal>2900);
select a.* from dept a , emp b where a.deptno=b.deptno and b.sal>2900;
select distinct a.* from dept a , emp b where a.deptno=b.deptno and b.sal>2900;
来自为知笔记(Wiz)
码字定式之SQL(5)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。