Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
0Activity
0 of .
Results for:
No results containing your search query
P. 1
Sub Queries

Sub Queries

Ratings: (0)|Views: 3 |Likes:
Published by shanu_123

More info:

Categories:Types, Research, Science
Published by: shanu_123 on Jul 08, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less

05/13/2014

pdf

text

original

 
1)selectemployeename,idanddeptname.(http://www.csee.umbc.edu/help/oracle8/server.815/a67779/ch4l.htm)(http://information.utep.edu/mmahmood/cis4365/slides/CHAP08.ppt#264,4,NaturalJoinExample)http://www.doc.mmu.ac.uk/STAFF/P.Quick/sql3.pptSol:----selectename,emp.deptno,dnamefromemp,deptwhere(emp.deptno,dname)in(selectdeptno,dnamefromdept)2)displaytheemployeedetailswhoearnsmoresalarythan'JONES'salaryfromemptable.sol:---selectename,salfromempwheresal>(selectsalfromempwhereempno=7566)3)Displaythenamesofallemployeeswhoearnlessthantheaveragesalaryinthecompany.sol:---selectename,sal,jobfromempwheresal<(selectavg(sal)fromemp);4)DisplaythedetailsoftheemployeeswhoaremanagedbythesamemanagerandworkinthesamedepartmentastheemployeeswithEMPLOYEEID7654and7902.(pairwisecomparisionsubquery)sol:---selectename,empno,job,mgr,deptnofromempwhere(mgr,deptno)in(selectmgr,deptnofromempwhereempnoin(7654,7902))andempnonotin(7654,7902)5)DisplaythedetailsoftheemployeeswhoaremanagedbythesamemanagerastheemployeeswithEMPLOYEEID7654or7902andworkinthesamedepartmentastheemployeeswithEMPLOYEEID7654or7902.sol:----selectename,empno,job,mgr,deptnofromempwheremgrin(selectmgrfromempwhereempnoin(7654,7844))anddeptnoin(selectdeptnofromempwhereempnoin(7654,7844))andempnonotin(7654,7844);6)selectsthename,job,salaryanddepartmentnumberofallemployeesexceptsa
 
lespeoplefromdepartmentnumber30.sol:---SELECTename,job,sal,deptnoFROMempWHERENOT(job='SALESMAN'ANDdeptno=30);7)Displaytheemployeedetailswhoworksin'BLAKE''sdepartment.sol:----SELECTename,deptnoFROMempWHEREdeptno=(SELECTdeptnoFROMempWHEREename='BLAKE')andenamenotlike'BLAKE';8)displaytheemployeelastnames,salaries,departmentnumbers,andaveragesalariesforalltheemployeeswhoearnmorethantheaveragesalaryintheirdepartmentsol:----selecta.ename,a.sal,a.deptno,b.avgsalfromempa,(selectdeptno,avg(sal)avgsalfromempgroupbydeptno)bwherea.deptno=b.deptnoanda.sal>b.avgsal;9)findallemprecordswhosedepartmentlocationisDALLASsol:----SELECTemp.ename,emp.JOB,emp.deptnoFROMempWHEREEXISTS(SELECT'x'FROMdeptdWHEREd.DEPTNO=emp.DEPTNOANDd.LOC='DALLAS')10)Displayename,job,deptno,dname,dlocforalltheemployees.(Ascalarsub-queryreturnsonlyasinglecolumnandasinglerow)sol:----SELECTemp.ename,emp.JOB,emp.deptno,(selectdnamefromdeptwheredept.deptno=emp.deptno)dname,(selectlocfromdeptwheredept.deptno=emp.deptno)dlocFROMemp;(or)SELECTemp.ename,emp.JOB,
 
emp.deptno,dnames.dname,dloc.locFROMempJOIN(selectdname,deptnofromdept)dnamesONemp.deptno=dnames.deptnoJOIN(selectloc,deptnofromdept)dloconemp.deptno=dloc.deptno11)displaythedepartmentnameinwhichemployeesarenotworking.sol:----selectdnamefromdeptwheredeptnonotin(selectdeptnofromempwheredeptnoisnotnull);(or)SELECTdnameFROMdeptWHERENOTEXISTS(SELECTdeptnoFROMempWHEREemp.deptno=dept.deptno)(correlatedsubquery)12)Displaythedepartmentnamesalongwithnumberofemployeesworkingineachdepartment;Sol:----SELECTd.deptno,d.dname,(SELECTcount(*)FROMempeWHEREe.deptno=d.deptno)AS"NumDept"FROMdeptd;13)displayallthemanagerdetailsbymakinguseof'exists'operator.sol:----selectempno,ename,deptno,jobfromempouterwhereexists(select'x'fromempwheremgr=outer.empno);14)Findalldepartmentsthatdonothaveanyemployees.Sol:---selectdeptno,dnamefromdeptdwherenotexists(select'x'fromempwheredeptno=d.deptno);15)UsingtheWITHclause,writeaquerytodisplaythedepartmentnameandtotalsalariesforthosedepartmentswhosetotalsalaryisgreaterthantheaveragesalaryacrossdepartments.sol:----

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->