Cyh的博客

Email:kissyan4916@163.com
posts - 26, comments - 19, trackbacks - 0, articles - 220

Oracle简单语法

Posted on 2009-02-16 19:11 啥都写点 阅读(141) 评论(0)  编辑  收藏

select deptno,dname

from dept

where deptno in (select deptno

                 from emp)

 

select deptno,dname

from dept

where deptno not in (select deptno

                     from emp)

                    

select empno,ename,sal

from emp

where sal > (select avg(sal)

             from emp)

 

select ename,sal

from emp

where sal > any (select min(sal)

             from emp

             group by deptno)

            

select ename,sal

from emp

where sal > all (select min(sal)

             from emp

             group by deptno)

 

select empno,ename,sal

from emp

where (deptno,sal) in (select deptno,max(sal)

                       from emp

                       group by deptno)

                      

--2           

select deptno,dname

from dept

where exists (select deptno

              from emp

              where dept.deptno = emp.deptno)

 

select deptno,dname

from dept

where not exists (select deptno

                  from emp

                  where dept.deptno = emp.deptno)

 

select a.empno,a.ename,a.sal

from emp a

where a.sal > (select avg(b.sal)

               from emp b

               where a.deptno = b.deptno)

              

select a.empno,a.ename,a.sal

from emp a,(select deptno,avg(sal) as avgsal

            from emp

            group by deptno) b

where a.deptno = b.deptno

  and a.sal > b.avgsal

                                      

select (select count(*) from dept) +

           (select count(*) from emp)

from dual

           

--3

select empno,ename,deptno

from emp

where deptno = 10 or deptno = 20

union

select empno,ename,deptno

from emp

where deptno = 10

order by empno

 

select empno,ename,deptno

from emp

where deptno = 10 or deptno = 20

union all

select empno,ename,deptno

from emp

where deptno = 10

order by empno

 

 

select empno,ename,deptno

from emp

where deptno = 10 or deptno = 20

intersect

select empno,ename,deptno

from emp

where deptno = 10

 

select empno,ename,deptno

from emp

where deptno = 10 or deptno = 20

minus

select empno,ename,deptno

from emp

where deptno = 10



                                                                                                       --    学海无涯
        


只有注册用户登录后才能发表评论。


网站导航: