2. ------------------------------ -------------------- --------------------
CCOST
----------
neha pentafour DCA
3000
mick perryridge PGDCA
10000
john downtown DCA
4000
PNAME SPLACE COURSE
------------------------------ -------------------- --------------------
CCOST
----------
sam pragathi PGDCA
15000
SQL> insert all into software values('raj','Gtalk','oracle',7000,5000,150) into software
values('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 software
values('rakesh','inventory','vb',10000,9000,200) select * from dual;
2 rows created.
SQL> select * from software;
PNAME TITLE
-------------------- --------------------
DEVIN SCOST DCOST SOLD
---------------------------------------- ---------- ---------- ----------
raj Gtalk
oracle 7000 5000 150
kumar chrome
vb 6000 4000 120
mani db2
oracle 7000 5000 150
PNAME TITLE
3. -------------------- --------------------
DEVIN SCOST DCOST SOLD
---------------------------------------- ---------- ---------- ----------
rakesh inventory
vb 10000 9000 200
SQL> 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 c
c++ 25000
ferdy 11-MAR-79 04-JUN-90 male c++
pascal 45000
shalini 30-APR-81 28-AUG-98 female c
c++ 30000
PNAME DOB DOJ SEX PROF1
-------------------- --------- --------- ------- ------------------------------
PROF2 SAL
-------------------- ----------
harini 11-MAY-82 19-SEP-99 female java
java 40000
4. QUERIES:
1.SQL> select avg(scost)from software where devin='oracle';
AVG(SCOST)
----------
7000
2.SQL> select
pname,trunc(months_between(sysdate,dob)/12)"age",trunc(months_between(sysdate,doj)/12)"experience
"from programmer;
PNAME age experience
-------------------- ---------- ----------
sri 31 15
ferdy 34 22
shalini 31 14
harini 30 13
3.SQL> select pname from studies where course='PGDCA';
PNAME
------------------------------
mick
sam
4.SQL> select max(sold) from software;
MAX(SOLD)
----------
200
5.SQL> select pname,dob from programmer where to_char(dob,’mon’)=’apr’;
PNAME
----------------
Sri
shalini
6.SQL> select min(ccost) from studies;
MIN(CCOST)
----------
3000
5. 7.SQL> select count(*) from studies where course='DCA';
COUNT(*)
----------
2
8.SQL> select sum(scost*sold-dcost) from software where devin='vb';
SUM(SCOST*SOLD-DCOST)
---------------------
2707000
9.SQL> select * from software where pname='rakesh';
PNAME TITLE
-------------------- --------------------
DEVIN SCOST DCOST SOLD
---------------------------------------- ---------- ---------- ----------
rakesh inventory
vb 10000 9000 200
10.SQL> select count(*) from studies where splace='pentafour';
COUNT(*)
----------
1
11.SQL> select * from software where scost*sold-dcost>5000;
PNAME TITLE
-------------------- --------------------
DEVIN SCOST DCOST SOLD
---------------------------------------- ---------- ---------- ----------
raj Gtalk
oracle 7000 5000 150
kumar chrome
vb 6000 4000 120
mani db2
oracle 7000 5000 150
PNAME TITLE
-------------------- --------------------
6. DEVIN SCOST DCOST SOLD
---------------------------------------- ---------- ---------- ----------
rakesh inventory
vb 10000 9000 200
12.SQL> select ceil(dcost/scost) from software;
CEIL(DCOST/SCOST)
-----------------
1
1
1
1
13.SQL> select *from software where scost*sold>=dcost;
PNAME TITLE
-------------------- --------------------
DEVIN SCOST DCOST SOLD
---------------------------------------- ---------- ---------- ----------
raj Gtalk
oracle 7000 5000 150
kumar chrome
vb 6000 4000 120
mani db2
oracle 7000 5000 150
PNAME TITLE
-------------------- --------------------
DEVIN SCOST DCOST SOLD
---------------------------------------- ---------- ---------- ----------
rakesh inventory
vb 10000 9000 200
14.SQL> select max(scost) from software where devin='vb';
MAX(SCOST)
----------
10000
7. 15.SQL> select avg(scost) from software where devin='oracle';
AVG(SCOST)
----------
7000
16.SQL> select count(*) from studies where splace='pragathi';
COUNT(*)
----------
1
17.SQL> select count(*) from studies where ccost between 9000 and 16000;
COUNT(*)
----------
2
18.SQL> select avg(ccost) from studies;
AVG(CCOST)
----------
8000
19.SQL> select pname from programmer where prof1='c'or prof2='c';
PNAME
--------------------
sri
shalini
20.SQL> select count(pname) from programmer where prof1 in('c','pascal')or prof2 in('c','pascal');
COUNT(PNAME)
------------
3
21.SQL> select count(pname) from programmer where prof1 not in('c','c++')or prof2 not in('c','c++');
COUNT(PNAME)
------------
2
8. 22.SQL> select round(max(months_between(sysdate,dob)/12)) from programmer where sex='male';
ROUND(MAX(MONTHS_BETWEEN(SYSDATE,DOB)/12))
------------------------------------------
34
23.SQL> select round(avg(months_between(sysdate,dob)/12)) from programmer where sex='female';
ROUND(AVG(MONTHS_BETWEEN(SYSDATE,DOB)/12))
------------------------------------------
31
24.SQL> select pname,trunc(months_between(sysdate,doj)/12) from programmer order by pname desc;
PNAME TRUNC(MONTHS_BETWEEN(SYSDATE,DOJ)/12)
-------------------- -------------------------------------
sri 15
shalini 14
harini 13
ferdy 22
25.SQL> select pname from programmer where to_char(dob,'mon')=to_char(sysdate,'mon');
PNAME
--------------------
ferdy
26.SQL> select count(*) from programmer where sex='female';
COUNT(*)
----------
2
27.SQL> select distinct(prof1) from programmer where sex='male';
PROF1
------------------------------
c
c++
9. 28.SQL> select avg(sal) from programmer;
AVG(SAL)
----------
35000
29.SQL> select count(*) from programmer where sal between 20000 and 40000;
COUNT(*)
----------
3
30.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 java
java 40000
31.SQL> select pname,title,scost from software where scost in(select max(scost) from software);
PNAME TITLE SCOST
-------------------- -------------------- ----------
rakesh inventory 10000
32.SQL> select 'Mr.'|| pname||'-has' || trunc(months_between(sysdate,doj)/12) || 'yeares of
experience'"programmer" from programmer where sex='male';
programmer
--------------------------------------------------------------------------------
Mr.sri-has15yeares of experience
Mr.ferdy-has22yeares of experience
SQL> spool off