jingxiao 2019-06-28
select dname from dept where deptno in(select deptno from emp);
2.exists 的用法?
select dname from dept where exists(select NULL from emp where emp.deptno=dept.deptno);
3.使用分组
select dname from dept where deptno in(select deptno from emp group by deptno having count(deptno)>=1);
select * from emp where sal > (select sal from emp where ename='SMITH')
使用exises
select * from emp A where exists (select null from emp B where A.SAL>B.SAL and Ename ='SMITH')
1.
select m.ename,n.ename from emp m left join emp n on m.mgr=n.empno
2.
select m.ename ,(select n.ename from emp n where n.empno=m.mgr )as bossname from emp m
select m.empno,m.ename,m.mgr,m.hiredate,n.empno,n.ename,n.hiredate from emp m join emp n on m.mgr=n.empno where m.hiredate<n.hiredate
1.
select dept.dname,emp.* from dept left join emp on dept.deptno=emp.deptno order by dept.dname
2.
select dept.dname,emp.* from dept left join emp Using(deptno) order by dept.dname
select ENAME,DNAME,job from emp JOIN dept on emp.deptno=dept.deptno where emp.job ='CLERK';
select job from emp group by job having min(sal)>1500
select * from emp where job in(select job from emp group by job having min(sal)>1500);
select * from emp join (select deptno from dept where dname='sales') tmp using (deptno);
select dname from dept where deptno in(select deptno from emp);
2.exists 的用法?
select dname from dept where exists(select NULL from emp where emp.deptno=dept.deptno);
3.使用分组
select dname from dept where deptno in(select deptno from emp group by deptno having count(deptno)>=1);
select ename from emp where sal>(select avg(sal) from emp );
select * from emp A where exists(select job from emp B where ename='SCOTT' AND A.JOB=B.JOB) AND eNAME !='scott';
select ename,sal,deptno from emp where sal in(select sal from emp where deptno='30') and deptno <>'30';
select ename,sal,deptno from emp where sal >ALL(select SAL from emp where deptno='30') and deptno <>'30';
select ename,sal,deptno from emp where sal >(select MAX(SAL) from emp where deptno='30') and deptno <>'30';
select count(empno),avg(sal),deptno from emp right join dept using(deptno) group by deptno
select empno,dname,sal+comm as wage from emp join dept using(deptno);
select dept.* from dept join emp using(deptno);
select job ,min(sal) from emp group by job
select min(sal) as sal,deptno from emp where job='manager' group by deptno
select (sal+comm)*12 as money,ename from emp order by money
deptno sal1 sal2 sal3
select sal from emp