Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
SCHEMAS:SQL> create table studies (pname varchar(30),splace varchar(20), course varchar(20), ccost number);Table created.S...
------------------------------ -------------------- --------------------    CCOST----------neha                      penta...
-------------------- --------------------DEVIN                                   SCOST DCOST                   SOLD-------...
QUERIES:1.SQL> select avg(scost)from software where devin=oracle;AVG(SCOST)----------     70002.SQL> selectpname,trunc(mon...
7.SQL> select count(*) from studies where course=DCA;  COUNT(*)----------       28.SQL> select sum(scost*sold-dcost) from ...
DEVIN                                   SCOST DCOST                   SOLD---------------------------------------- -------...
15.SQL> select avg(scost) from software where devin=oracle;AVG(SCOST)----------     700016.SQL> select count(*) from studi...
22.SQL> select round(max(months_between(sysdate,dob)/12)) from programmer where sex=male;ROUND(MAX(MONTHS_BETWEEN(SYSDATE,...
28.SQL> select avg(sal) from programmer;  AVG(SAL)----------    3500029.SQL> select count(*) from programmer where sal bet...
Upcoming SlideShare
Loading in …5
×

Sql2

166 views

Published on

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

Sql2

  1. 1. SCHEMAS:SQL> create table studies (pname varchar(30),splace varchar(20), course varchar(20), ccost number);Table created.SQL> create table software(pname varchar(20),title varchar(20),devin varchar(40),scost number,dcostnumber,sold number);Table created.SQL> create table programmer(pname varchar(20),dob date,doj date,sex char(7),prof1 varchar(30),prof2varchar(20),sal number);Table created.SQL> insert into studies values(neha,pentafour,DCA,3000);1 row created.SQL> insert into studies values(mick,perryridge,PGDCA,10000);1 row created.SQL> insert into studies values(john,downtown,DCA,4000);1 row created.SQL> select * from studies;PNAME SPLACE COURSE------------------------------ -------------------- -------------------- CCOST----------neha pentafour DCA 3000mick perryridge PGDCA 10000john downtown DCA 4000SQL> insert into studies values(sam,pragathi,PGDCA,15000);1 row created.SQL> select * from studies;PNAME SPLACE COURSE
  2. 2. ------------------------------ -------------------- -------------------- CCOST----------neha pentafour DCA 3000mick perryridge PGDCA 10000john downtown DCA 4000PNAME SPLACE COURSE------------------------------ -------------------- -------------------- CCOST----------sam pragathi PGDCA 15000SQL> insert all into software values(raj,Gtalk,oracle,7000,5000,150) into softwarevalues(kumar,chrome,vb,6000,4000,120) select * from dual;2 rows created.SQL> insert all into software values(mani,db2,oracle,7000,5000,150) into softwarevalues(rakesh,inventory,vb,10000,9000,200) select * from dual;2 rows created.SQL> select * from software;PNAME TITLE-------------------- --------------------DEVIN SCOST DCOST SOLD---------------------------------------- ---------- ---------- ----------raj Gtalkoracle 7000 5000 150kumar chromevb 6000 4000 120mani db2oracle 7000 5000 150PNAME TITLE
  3. 3. -------------------- --------------------DEVIN SCOST DCOST SOLD---------------------------------------- ---------- ---------- ----------rakesh inventoryvb 10000 9000 200SQL> insert all into programmer values(sri,to_date(8-apr-1981,dd-mon-yyyy),to_date(13-feb-1998,dd-mon-yyyy),male,c,c++,25000) into programmer values(ferdy,to_date(11-mar-1979,dd-mon-yyyy),to_date(4-jun-1990),male,c++,pascal,45000) select * from dual;2 rows created.SQL> insert all into programmer values(shalini,to_date(30-apr-1981,dd-mon-yyyy),to_date(28-aug-1998,dd-mon-yyyy),female,c,c++,30000) into programmer values(harini,to_date(11-may-1982,dd-mon-yyyy),to_date(19-sep-1999),female,java,java,40000) select * from dual;2 rows created.SQL> select * from programmer;PNAME DOB DOJ SEX PROF1-------------------- --------- --------- ------- ------------------------------PROF2 SAL-------------------- ----------sri 08-APR-81 13-FEB-98 male cc++ 25000ferdy 11-MAR-79 04-JUN-90 male c++pascal 45000shalini 30-APR-81 28-AUG-98 female cc++ 30000PNAME DOB DOJ SEX PROF1-------------------- --------- --------- ------- ------------------------------PROF2 SAL-------------------- ----------harini 11-MAY-82 19-SEP-99 female javajava 40000
  4. 4. QUERIES:1.SQL> select avg(scost)from software where devin=oracle;AVG(SCOST)---------- 70002.SQL> selectpname,trunc(months_between(sysdate,dob)/12)"age",trunc(months_between(sysdate,doj)/12)"experience"from programmer;PNAME age experience-------------------- ---------- ----------sri 31 15ferdy 34 22shalini 31 14harini 30 133.SQL> select pname from studies where course=PGDCA;PNAME------------------------------micksam4.SQL> select max(sold) from software; MAX(SOLD)---------- 2005.SQL> select pname,dob from programmer where to_char(dob,’mon’)=’apr’;PNAME----------------Srishalini6.SQL> select min(ccost) from studies;MIN(CCOST)---------- 3000
  5. 5. 7.SQL> select count(*) from studies where course=DCA; COUNT(*)---------- 28.SQL> select sum(scost*sold-dcost) from software where devin=vb;SUM(SCOST*SOLD-DCOST)--------------------- 27070009.SQL> select * from software where pname=rakesh;PNAME TITLE-------------------- --------------------DEVIN SCOST DCOST SOLD---------------------------------------- ---------- ---------- ----------rakesh inventoryvb 10000 9000 20010.SQL> select count(*) from studies where splace=pentafour; COUNT(*)---------- 111.SQL> select * from software where scost*sold-dcost>5000;PNAME TITLE-------------------- --------------------DEVIN SCOST DCOST SOLD---------------------------------------- ---------- ---------- ----------raj Gtalkoracle 7000 5000 150kumar chromevb 6000 4000 120mani db2oracle 7000 5000 150PNAME TITLE-------------------- --------------------
  6. 6. DEVIN SCOST DCOST SOLD---------------------------------------- ---------- ---------- ----------rakesh inventoryvb 10000 9000 20012.SQL> select ceil(dcost/scost) from software;CEIL(DCOST/SCOST)----------------- 1 1 1 113.SQL> select *from software where scost*sold>=dcost;PNAME TITLE-------------------- --------------------DEVIN SCOST DCOST SOLD---------------------------------------- ---------- ---------- ----------raj Gtalkoracle 7000 5000 150kumar chromevb 6000 4000 120mani db2oracle 7000 5000 150PNAME TITLE-------------------- --------------------DEVIN SCOST DCOST SOLD---------------------------------------- ---------- ---------- ----------rakesh inventoryvb 10000 9000 20014.SQL> select max(scost) from software where devin=vb;MAX(SCOST)---------- 10000
  7. 7. 15.SQL> select avg(scost) from software where devin=oracle;AVG(SCOST)---------- 700016.SQL> select count(*) from studies where splace=pragathi; COUNT(*)---------- 117.SQL> select count(*) from studies where ccost between 9000 and 16000; COUNT(*)---------- 218.SQL> select avg(ccost) from studies;AVG(CCOST)---------- 800019.SQL> select pname from programmer where prof1=cor prof2=c;PNAME--------------------srishalini20.SQL> select count(pname) from programmer where prof1 in(c,pascal)or prof2 in(c,pascal);COUNT(PNAME)------------ 321.SQL> select count(pname) from programmer where prof1 not in(c,c++)or prof2 not in(c,c++);COUNT(PNAME)------------ 2
  8. 8. 22.SQL> select round(max(months_between(sysdate,dob)/12)) from programmer where sex=male;ROUND(MAX(MONTHS_BETWEEN(SYSDATE,DOB)/12))------------------------------------------ 3423.SQL> select round(avg(months_between(sysdate,dob)/12)) from programmer where sex=female;ROUND(AVG(MONTHS_BETWEEN(SYSDATE,DOB)/12))------------------------------------------ 3124.SQL> select pname,trunc(months_between(sysdate,doj)/12) from programmer order by pname desc;PNAME TRUNC(MONTHS_BETWEEN(SYSDATE,DOJ)/12)-------------------- -------------------------------------sri 15shalini 14harini 13ferdy 2225.SQL> select pname from programmer where to_char(dob,mon)=to_char(sysdate,mon);PNAME--------------------ferdy26.SQL> select count(*) from programmer where sex=female; COUNT(*)---------- 227.SQL> select distinct(prof1) from programmer where sex=male;PROF1------------------------------cc++
  9. 9. 28.SQL> select avg(sal) from programmer; AVG(SAL)---------- 3500029.SQL> select count(*) from programmer where sal between 20000 and 40000; COUNT(*)---------- 330.SQL> select * from programmer where prof1 not in(c,c++,pascal) and prof2 not in(c,c++,pascal);PNAME DOB DOJ SEX PROF1-------------------- --------- --------- ------- ------------------------------PROF2 SAL-------------------- ----------harini 11-MAY-82 19-SEP-99 female javajava 4000031.SQL> select pname,title,scost from software where scost in(select max(scost) from software);PNAME TITLE SCOST-------------------- -------------------- ----------rakesh inventory 1000032.SQL> select Mr.|| pname||-has || trunc(months_between(sysdate,doj)/12) || yeares ofexperience"programmer" from programmer where sex=male;programmer--------------------------------------------------------------------------------Mr.sri-has15yeares of experienceMr.ferdy-has22yeares of experienceSQL> spool off

×