SQL Query Assignment
SQL Query Assignment
#1. Find out the selling cost AVG for packages developed in Pascal.
#3.Display the Names of those who have done the DAP Course.
#4.Display the Names and Date of Births of all Programmers Born in January.
#8.How much revenue has been earned thru sales of Packages Developed in C.
#12.Display the Details of Packages for which Development Cost have been recovered.
SELECT COUNT (NAME) AS NO_OF_PROGRAMMERS FROM STUDIES WHERE CCOST>=5000 AND CCOST<=10000;
SELECT COUNT (NAME) AS PROGRAMMERS FROM PROGRAMMER WHERE PROF1 IN ('COBOL' ,'PASCAL' ) OR PROF2 IN
('COBOL' ,'PASCAL' );
SELECT COUNT (NAME) AS PROGRAMMERS FROM PROGRAMMER WHERE PROF1 NOT IN ('C','PASCAL') AND PROF2 NOT
IN ('C','PASCAL');
#21.How old is the Oldest Male Programmer.
#23.Calculate the Experience in Years for each Programmer and Display with their names in Descending order.
SELECT NAME, FLOOR ((SYSDATE - DOJ)/365) AS EXPERIENCE FROM PROGRAMMER ORDER BY NAME DESC;
#24.Who are the Programmers who celebrate their Birthday’s During the Current Month?
SELECT NAME FROM PROGRAMMER WHERE SALARY BETWEEN 2000 AND 4000;
#29.Display the details of those who don’t know Clipper, COBOL or PASCAL.
SELECT * FROM PROGRAMMER WHERE PROF1 NOT IN ('CLIPPER','COBOL','PASCAL') AND PROF2 NOT IN
('CLIPPER','COBOL','PASCAL');
#33.Display the sales cost of the packages Developed by each Programmer Language wise.
per
#34.Display each language name with AVG Development Cost, AVG Selling Cost and
#35.Display each programmer’s name, costliest and cheapest Packages Developed by him or her.
#36.Display each institute name with number of Courses, Average Cost per Course.
SELECT * FROM PROGRAMMER WHERE PROF1 NOT IN ('C','C++') AND PROF2 NOT IN ('C','C++');
#41. Display the Number of Packages in Each Language for which Development Cost is less than 1000
#43. Display the total SCOST, DCOST and amount to Be Recovered for each
Programmer for Those Whose Cost has not yet been Recovered.
HAVING SUM(DCOST)>SUM(SOLD*SCOST);
#44.Display Highest, Lowest and Average Salaries for those earning more than 2000.
SELECT MAX(SALARY), MIN(SALARY), AVG(SALARY) FROM PROGRAMMER WHERE SALARY > 2000;
SELECT * FROM PROGRAMMER WHERE SALARY=(SELECT MAX(SALARY) FROM PROGRAMMER WHERE PROF1 LIKE 'C' OR
PROF2 LIKE 'C');
SELECT * FROM PROGRAMMER WHERE SALARY=(SELECT MAX(SALARY) FROM PROGRAMMER WHERE (PROF1 LIKE
'COBOL' OR PROF2 LIKE 'COBOL')) AND SEX LIKE 'F';
#47.Display the names of the highest paid programmers for each Language.
SELECT DISTINCT NAME, SALARY, PROF1 FROM PROGRAMMER WHERE (SALARY,PROF1) IN (SELECT MAX(SALARY),PROF1
FROM PROGRAMMER GROUP BY PROF1);
#48.Who is the least experienced Programmer.
select pname from programmer where gender = 'm' and (prof1 = 'pascal' or prof2 = 'pascal') and FLOOR((SYSDATE-
DOJ)/365) = (SELECT MAX(FLOOR((SYSDATE-DOJ)/365)) FROM PROGRAMMER);
SELECT PROF1 FROM PROGRAMMER GROUP BY PROF1 HAVING PROF1 NOT IN (SELECT PROF2 FROM PROGRAMMER)
AND COUNT(PROF1)=1 UNION SELECT PROF2 FROM PROGRAMMER GROUP BY PROF2 HAVING PROF2 NOT IN (SELECT
PROF1 FROM PROGRAMMER) AND COUNT(PROF2)=1;
SELECT NAME
FROM PROGRAMMER
WHERE PROF1 IN (SELECT PROF1
FROM PROGRAMMER
GROUP BY PROF1
HAVING PROF1 NOT IN (SELECT PROF2 FROM PROGRAMMER)
AND COUNT(PROF1)=1
UNION
SELECT PROF2
FROM PROGRAMMER
GROUP BY PROF2
HAVING PROF2 NOT IN (SELECT PROF1 FROM PROGRAMMER)
AND COUNT(PROF2)=1))
UNION
SELECT NAME
FROM PROGRAMMER
WHERE PROF2 IN (SELECT PROF1
FROM PROGRAMMER
GROUP BY PROF1
HAVING PROF1 NOT IN (SELECT PROF2 FROM PROGRAMMER)
AND COUNT(PROF1)=1
UNION
SELECT PROF2
FROM PROGRAMMER
GROUP BY PROF2
HAVING PROF2 NOT IN (SELECT PROF1 FROM PROGRAMMER)
AND COUNT(PROF2)=1))
#52.Who is the Youngest Programmer knowing DBASE?
#53.Which Female Programmer earning more than 3000 does not know C, C++, ORACLE or DBASE?
SELECT * FROM PROGRAMMER WHERE SEX = 'F' AND SALARY >3000 AND (PROF1 NOT IN('C','C++','ORACLE','DBASE') OR
PROF2 NOT IN('C','C++','ORACLE','DBASE'));
SELECT SPLACE FROM STUDIES GROUP BY SPLACE HAVING COUNT(SPLACE)= (SELECT MAX(COUNT(SPLACE)) FROM
STUDIES GROUP BY SPLACE);
SELECT COURSE FROM STUDIES WHERE CCOST = (SELECT MAX(CCOST) FROM STUDIES);
SELECT COURSE FROM STUDIES GROUP BY COURSE HAVING COUNT(COURSE)= (SELECT MAX(COUNT(COURSE)) FROM
STUDIES GROUP BY COURSE);
SELECT SPLACE FROM STUDIES WHERE CCOST = (SELECT MAX(CCOST) FROM STUDIES);
#58.Display the name of the Institute and Course, which has below AVG course fee.
SELECT SPLACE,COURSE FROM STUDIES WHERE CCOST < (SELECT AVG(CCOST) FROM STUDIES);
#59.Display the names of the courses whose fees are within 1000 (+ or -) of the Average Fee,
SELECT COURSE FROM STUDIES WHERE CCOST < (SELECT AVG(CCOST)+1000 FROM STUDIES) AND CCOST > (SELECT
AVG(CCOST)-1000 FROM STUDIES);
SELECT TITLE,DCOST FROM SOFTWARE WHERE DCOST = (SELECT MAX(DCOST) FROM SOFTWARE);
#61.Which course has below AVG number of Students?
SELECT COURSE FROM STUDIES GROUP BY COURSE HAVING COUNT(NAME)<(SELECT AVG(COUNT(NAME)) FROM
STUDIES GROUP BY COURSE) ;
SELECT TITLE,SCOST FROM SOFTWARE WHERE SCOST = (SELECT MIN(SCOST) FROM SOFTWARE);
#63.Who Developed the Package that has sold the least number of copies?
SELECT NAME,SOLD FROM SOFTWARE WHERE SOLD = (SELECT MIN(SOLD) FROM SOFTWARE);
#64.Which language has used to develop the package, which has the highest sales amount?
SELECT DEV_IN,SCOST FROM SOFTWARE WHERE SCOST = (SELECT MAX(SCOST) FROM SOFTWARE);
#65. How many copies of package that has the least difference between development and selling cost where sold.
SELECT SOLD,TITLE FROM SOFTWARE WHERE TITLE = (SELECT TITLE FROM SOFTWARE WHERE (DCOST-SCOST)=(SELECT
MIN(DCOST-SCOST) FROM SOFTWARE);
SELECT TITLE FROM SOFTWARE WHERE DCOST = (SELECT MAX(DCOST) FROM SOFTWARE WHERE DEV_IN LIKE 'PASCAL');
SELECT DEV_IN FROM SOFTWARE GROUP BY DEV_IN HAVING MAX(DEV_IN) = (SELECT MAX(DEV_IN) FROM SOFTWARE);
SELECT NAME FROM SOFTWARE GROUP BY NAME HAVING MAX(NAME) = (SELECT MAX(NAME) FROM SOFTWARE);
SELECT NAME,DCOST FROM SOFTWARE WHERE DCOST = (SELECT MAX(DCOST) FROM SOFTWARE);
#70. Display the names of the packages, which have sold less than the AVG number of copies.
SELECT TITLE FROM SOFTWARE WHERE SOLD < (SELECT AVG(SOLD) FROM SOFTWARE);
#71.Who are the authors of the Packages, which have recovered more than double the Development cost?
#72.Display the programmer Name and the cheapest packages developed by them in each language.
SELECT NAME,TITLE FROM SOFTWARE WHERE DCOST IN (SELECT MIN(DCOST) FROM SOFTWARE GROUP BY DEV_IN);
#73.Display the language used by each programmer to develop the Highest Selling and Lowest-selling package.
SELECT NAME, DEV_IN FROM SOFTWARE WHERE SOLD IN (SELECT MAX(SOLD) FROM SOFTWARE GROUP BY NAME)
UNION SELECT NAME, DEV_IN FROM SOFTWARE WHERE SOLD IN (SELECT MIN(SOLD) FROM SOFTWARE GROUP BY
NAME);
SELECT NAME FROM PROGRAMMER WHERE DOB=(SELECT (MAX(DOB)) FROM PROGRAMMER WHERE
TO_CHAR(DOB,'YYYY') LIKE '1965');
SELECT NAME FROM PROGRAMMER WHERE DOJ=(SELECT (MIN(DOJ)) FROM PROGRAMMER WHERE
TO_CHAR(DOJ,'YYYY') LIKE '1992');
SELECT PROF1 FROM PROGRAMMER GROUP BY PROF1 HAVING COUNT(PROF1)=(SELECT MAX(COUNT(PROF1)) FROM
PROGRAMMER GROUP BY PROF1) OR COUNT(PROF2)=(SELECT MAX(COUNT(PROF2)) FROM PROGRAMMER GROUP BY
PROF2)
UNION
SELECT PROF2 FROM PROGRAMMER GROUP BY PROF2 HAVING COUNT(PROF1)=(SELECT MAX(COUNT(PROF1)) FROM
PROGRAMMER GROUP BY PROF1) OR COUNT(PROF2)=(SELECT MAX(COUNT(PROF2)) FROM PROGRAMMERGROUP BY
PROF2);
#79.Who are the male programmers earning below the AVG salary of Female Programmers?
SELECT NAME FROM PROGRAMMER WHERE SEX = 'M' AND SALARY < (SELECT(AVG(SALARY))FROM PROGRAMMER
WHERE SEX = 'F');
#80.Who are the Female Programmers earning more than the Highest Paid?
SELECT NAME FROM PROGRAMMER WHERE SEX = 'F' AND SALARY > (SELECT(MAX(SALARY)) FROM PROGRAMMER
WHERE SEX = 'M');
#81.Which language has been stated as the proficiency by most of the Programmers?
SELECT PROF1 FROM PROGRAMMER GROUP BY PROF1 HAVING PROF1 = (SELECT MAX(PROF1) FROM PROGRAMMER);
#82.Display the details of those who are drawing the same salary.
select name, salary from programmer where salary = any(select salary from programmer p group by salary having
salary=p.salary and count(*)>1);
#83.Display the details of the Software Developed by the Male Programmers Earning More than 3000/-.
select software.* from programmer p,software s where p.name=s.name and salary>3000 and sex='m';
#84. Display the details of the packages developed in Pascal by the Female Programmers.
select s.* from programmer p,software s where p.name=s.name and sex='f' and dev_in='pascal';
#85. Display the details of the Programmers who joined before 1990.
#86. Display the details of the Software Developed in C By female programmers of Pragathi.
select s.* from software s,studies st,programmer p where s.name=st.name and p.name=s.name and sex='f' and
splace='pragathi';
#87. Display the number of packages, No. of Copies Sold and sales value of each programmer institute wise.
#88.Display the details of the software developed in DBASE by Male Programmers, who
#89.Display the details of the software Developed by the male programmers Born
select software.* from programmer p,software s where s.name=p.name and sex='m' and to_char(dob,'yy')<64 or sex='f'
and To_char(dob,'yy')>75);
#90.Display the details of the software that has developed in the language which is
select s.* from programmer p,software s where s.name=p.name and (dev_in <> prof1 and dev_in <> prof2);
#91.Display the details of the software developed by the male students of Sabhari.
select s.* from programmer p,software s,studies st where p.name=s.name and s.name=st.name and sex='m' and
splace='sabhari';
#92.Display the names of the programmers who have not developed any packages.
select name from programmer where name not in(select name from software);
#93.What is the total cost of the Software developed by the programmers of Apple?
select a.name,a.doj from programmer a,programmer b where a.doj=b.doj and a.name <> b.name;
#95.Who are the programmers who have the same Prof2?
select name from programmer where prof2 = any(select prof2 from programmer group by prof2 having count(*) >1);
#97.In which institute does the person who developed the costliest package studied.
select splace from software st,studies s where s.name=st.name group by splace,dcost having max(dcost)=(select
max(dcost) from software);
#98.Which language listed in prof1, prof2 has not been used to develop any package.
select prof1 from programmer where prof1 not in(select dev_in from software) union select prof2 from programmer
where prof2 not in(select dev_in from software);
#99.How much does the person who developed the highest selling package earn and what course did HE/SHE undergo
select p1.salary,s2.course from programmer p1,software s1,studies s2 where p1.name=s1.name and s1.name=s2.name
and scost=(select max(scost) from software);
#100.What is the AVG salary for those whose software sales is more than 50,000/-.
#101.How many packages were developed by students, who studied in institute that charge the lowest course fee?
select count(s.name) from software s,studies st where s.name=st.name group by s.name,ccost having min(ccost)=(select
min(ccost) from studies);
#102.How many packages were developed by the person who developed the cheapest package, where did HE/SHE
study?
select count(*) from programmer p,software s where s .name=p.name group by dev_in having min(dcost)=(select
min(dcost) from software);
#103.How many packages were developed by the female programmers earning more than the highest paid male
programmer?
select count(dev_in) from programmer p,software s where s.name=p.name and sex='f' and salary>(select max(salary)
from programmer p,software s where s.name=p.name and sex='m');
#104. How many packages are developed by the most experienced programmer form BDPS.
select count(x.name) from software x, programmer y, studies x where months_between(sysdate, y.doj)/12) = (select
max(months_between(sysdate,y.doj)/12) from programmer y, studies = where x.splace = 'BDPS' and y.name = z.name)
and x.name=y.name andz.splace='BDPS';
#105.List the programmers (form the software table) and the institutes they studied.
select name,splace from studies where name in(select name from software);
#106.List each PROF with the number of Programmers having that PROF and the number of the packages in that
PROF.
select count(*),sum(scost*sold-dcost) "PROFIT" from software where dev_in in (select prof1 from programmer) group
by dev_in;
#107.List the programmer names (from the programmer table) and No. Of Packages each has developed.