Module 3 Assignement Solution

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

USE JARVIS

CREATE TABLE STUDIES


(
Student_id INT PRIMARY KEY,
Student_Name VARCHAR(20),
Student_place VARCHAR(20),
Course VARCHAR(20),
Cost Int
);

INSERT INTO STUDIES VALUES


(1, 'ANAND', 'SABHARI', 'PGDCA', 45000),
(2, 'ALTAF', 'COIT', 'DCA', 7200),
(3, 'JULIANA', 'BITS', 'MCA', 22000),
(4, 'KAMALA', 'PRAGATHI', 'DCP', 5000),
(5, 'MARY', 'SABHARI', 'PGDCA', 4600),
(6, 'NELSON', 'PRAGATHI', 'DAP', 6200),
(7, 'PATRICK', 'SABHARI', 'DCA', 5200),
(8, 'QADIR', 'APPLE', 'HDCP', 14000),
(9, 'RAMESH', 'SABHARI', 'PGDCA', 4500),
(10,'REBECCA', 'BPILLANI', 'DCA', 11000),
(11, 'REMITHA', 'BDPS', 'DCS', 6000),
(12, 'REVATHI', 'SABHARI', 'DAP', 5000),
(13, 'VIJAYA', 'BDPS', 'DCA', 48000);

SELECT * FROM STUDIES;

-- CREATE SOFTWARE TABLE


CREATE TABLE SOFTWARE
(
Student_id INT REFERENCES STUDIES(Student_id),
Title VARCHAR(20),
DEV_IN VARCHAR (10),
SCOST INT,
DCOST INT,
SOLD INT
);

INSERT INTO SOFTWARE VALUES


(1, 'PARACHUTES', 'BASIC', 399, 6000, 43),
(1, 'VIDEO TITLING PACK', 'PASCAL', 7500, 16000, 9),
(3, 'INVENTORY CONTROL', 'COBOL', 3000, 3500, 0),
(4, 'PAYROLL PACKAGE', 'DBASE', 9000, 20000, 7),
(5, 'FINANCIAL ACC.S/W', 'ORACLE', 18000, 85000, 4),
(7, 'CODE GENERATION', 'COBOL', 4500, 20000, 23),
(8, 'READ ME', 'C++', 300, 1200, 84),
(8, 'BOMBS AWAY', 'ASSEMBLY', 750, 5000, 11),
(8, 'VACCINES', 'C', 1900, 3400, 21),
(9, 'HOTEL MANAGEMENT', 'DBASE', 12000, 3500, 4),
(9, 'DEAD LEE', 'PASCAL', 599, 4500, 73),
(11, 'PC UTILITIES', 'C', 725, 5000, 51),
(11, 'TSR HELP PACKAGE', 'ASSEMBLY', 2500, 6000, 6),
(12, 'HOSPITAL MANAGEMENT', 'PASCAL', 1100, 75000, 2),
(12, 'QUIZ MASTER', 'BASIC', 3200, 2100, 15),
(13, 'ISR EDITION', 'C', 900, 700, 6);

SELECT * FROM SOFTWARE;


-- CREATE PROGRAMMER TABLE

CREATE TABLE PROGRAMMER


(
P_ID INT REFERENCES STUDIES(Student_id),
DOB DATE,
DOJ DATE,
GENDER CHAR CHECK(GENDER IN ('M','F')),
PROF1 VARCHAR(15),
PROF2 VARCHAR(15),
SALARY INT CHECK (SALARY>0)
);

INSERT INTO PROGRAMMER VALUES


(1,'21-APR-66','21-APR-92','M','PASCAL','BASIC',3200),
(2,'02-JUL-64','13-NOV-90','M','CLIPPER','COBOL',2800),
(3,'31-JAN-68','21-APR-90','F','COBOL','DBASE',3000),
(4,'30-OCT-68','02-JAN-92','F','C','DBASE',2900),
(5,'24-JUN-70','01-FEB-91','F','C++','ORACLE',4500),
(6,'11-SEP-85','11-OCT-89','M','COBOL','DBASE',2500),
(7,'10-NOV-65','21-APR-90','M','PASCAL','CLIPPER',2800),
(8,'31-AUG-65','21-APR-91','M','ASSEMBLY','C',3000),
(9,'03-MAY-67','28-FEB-91','M','PASCAL','DBASE',3200),
(10,'01-JAN-67','01-DEC-90','F','BASIC','COBOL',2500),
(11,'19-APR-70','20-APR-93','F','C','ASSEMBLY',3600),
(12,'02-DEC-69','02-JAN-92','F','PASCAL','BASIC',3700),
(13,'14-DEC-65','02-MAY-92','F','FOXPRO','C',3500);

SELECT * FROM PROGRAMMER;


--1) How many Programmers Don’t know PASCAL and C

SELECT * FROM PROGRAMMER;


SELECT COUNT(P_ID) AS TOTAL FROM PROGRAMMER
WHERE PROF1 NOT IN ('C', 'PASCAL') OR PROF2 NOT IN ('C', 'PASCAL');

--2) Display the details of those who don’t know Clipper, COBOL or PASCAL.

SELECT
S.STUDENT_NAME,
P.*
FROM PROGRAMMER P INNER JOIN STUDIES S ON S.Student_id = P.P_ID
WHERE PROF1 NOT IN ('CLIPPER', 'COBOL', 'PASCAL')
AND PROF2 NOT IN ('CLIPPER', 'COBOL', 'PASCAL');

/*3) Display each language name with AVG Development Cost,


AVG Selling Cost and AVG Price per Copy.*/
SELECT * FROM SOFTWARE;

SELECT
DEV_IN,
AVG(SCOST) AS AVG_SCOST,
AVG(DCOST) AS AVG_DCOST,
(AVG(SCOST))/(SUM(SOLD)) AS AVG_PRICE_PER_COPY
FROM SOFTWARE GROUP BY DEV_IN;

/*4) List the programmer names (from the programmer table)


and No. Of Packages each has developed.*/
SELECT
S.STUDENT_NAME,
COUNT (SO.DEV_IN) AS NO_OF_PACKAGES_DEVELOPED
FROM PROGRAMMER P INNER JOIN STUDIES S ON S.Student_id = P.P_ID
INNER JOIN SOFTWARE SO ON P.P_ID = SO.Student_id
GROUP BY S.STUDENT_NAME;

/* 5) List each PROFIT with the number of Programmers


having that PROF and the number of the packages in that PROF.*/
SELECT * FROM PROGRAMMER;
SELECT * FROM SOFTWARE;
SELECT
COUNT(S.DEV_IN) AS NO_OF_PACKAGES,
COUNT(P.P_ID) NO_OF_PROGRAMMERS,
SUM(S.SCOST*S.SOLD-S.DCOST) PROFIT,
S.DEV_IN
FROM SOFTWARE S INNER JOIN PROGRAMMER P ON S.STUDENT_ID = P.P_ID
WHERE DEV_IN IN (SELECT PROF1 FROM PROGRAMMER) OR DEV_IN IN (SELECT PROF2 FROM
PROGRAMMER)
GROUP by DEV_IN;

--6) How many packages are developed by the most experienced programmer from BDPS.
SELECT
COUNT(SO.DEV_IN) AS TOTAL,
P.DOJ,
S.Student_place
FROM SOFTWARE SO INNER JOIN STUDIES S ON S.Student_id = SO.Student_id
INNER JOIN PROGRAMMER P ON P.P_ID = SO.Student_id
WHERE S.Student_place = 'BDPS'
GROUP BY P.DOJ, S.Student_place HAVING P.DOJ = (SELECT MAX(DOJ) FROM PROGRAMMER );

/*7)How many packages were developed by the female programmers


earning more than the highest paid male programmer?*/

SELECT
COUNT(SO.DEV_IN) AS TOTAL_PACKAGES_DEVELOPED
FROM SOFTWARE SO INNER JOIN PROGRAMMER P ON SO.Student_id = P.P_ID
WHERE P.GENDER = 'F' AND
P.SALARY > (SELECT MAX(SALARY) FROM PROGRAMMER WHERE GENDER = 'M')
GROUP BY SO.DEV_IN;

/*8)How much does the person who developed the highest selling package
earn and what course did HE/SHE undergo.*/
SELECT * FROM PROGRAMMER;
SELECT * FROM SOFTWARE;
SELECT * FROM STUDIES;

SELECT
SO.STUDENT_ID,
S.COURSE,
P.SALARY
FROM SOFTWARE SO INNER JOIN STUDIES S ON S.Student_id = SO.Student_id
INNER JOIN PROGRAMMER P ON P.P_ID = SO.Student_id
WHERE SO.SOLD IN (SELECT MAX(SOLD) FROM SOFTWARE);

/*9)In which institute did the person who developed the costliest package study?*/

SELECT STUDENT_PLACE
FROM STUDIES S INNER JOIN SOFTWARE SO ON S.Student_id = SO.Student_id
WHERE SCOST IN (SELECT MAX(SCOST) FROM SOFTWARE);

/*10)Display the names of the programmers who have not developed any packages.*/
SELECT * FROM PROGRAMMER;
SELECT * FROM SOFTWARE;
SELECT * FROM STUDIES;

SELECT STUDIES.STUDENT_NAME, P_ID FROM PROGRAMMER


INNER JOIN STUDIES ON STUDIES.Student_id = PROGRAMMER.P_ID
WHERE P_ID NOT IN (SELECT STUDENT_ID FROM SOFTWARE);

/*11) Display the details of the software that has developed in the
language which is neither the first nor the second proficiency*/

SELECT DEV_IN FROM SOFTWARE


INNER JOIN PROGRAMMER ON SOFTWARE.Student_id = PROGRAMMER.P_ID
WHERE (SOFTWARE.DEV_IN <> PROGRAMMER.PROF1
AND SOFTWARE.DEV_IN <> PROGRAMMER.PROF2);

/*12) Display the details of the software Developed


by the male programmers Born before 1965
and female programmers born after 1975*/

SELECT
SO.DEV_IN,
P.GENDER,
P.DOB
FROM PROGRAMMER P INNER JOIN SOFTWARE SO ON SO.Student_id = P.P_ID
WHERE (P.GENDER IN (SELECT GENDER FROM PROGRAMMER WHERE GENDER = 'M')
AND YEAR(P.DOB) < 1965)
AND (P.GENDER IN (SELECT GENDER FROM PROGRAMMER WHERE GENDER = 'F')
AND YEAR(P.DOB) > 1975);

SELECT * FROM PROGRAMMER WHERE YEAR(DOB) < 1965 AND GENDER = 'M';

/*13)Display the number of packages, No. of Copies Sold and sales value
of each programmer institute wise.*/

SELECT * FROM STUDIES;


SELECT * FROM SOFTWARE;

SELECT
S.STUDENT_PLACE,
COUNT(SO.DEV_IN) AS NO_OF_PACKAGES,
SUM(SO.SOLD) AS NO_OF_COPIES_SOLD,
SUM(SO.SCOST * SO.SOLD) AS SALES_VALUE
FROM SOFTWARE SO INNER JOIN STUDIES S ON SO.Student_id = S.Student_id
GROUP BY S.Student_place;

/*14) Display the details of the Software Developed by the


Male Programmers Earning More than 3000*/

SELECT * FROM SOFTWARE SO


INNER JOIN PROGRAMMER P ON SO.Student_id = P.P_ID
WHERE P.GENDER = 'M' AND P.SALARY > 3000;

/*15) Who are the Female Programmers earning more than the Highest Paid male*/
SELECT * FROM STUDIES;
SELECT
S.STUDENT_NAME,
P.GENDER,
P.SALARY
FROM STUDIES S INNER JOIN PROGRAMMER P ON S.Student_id = P.P_ID
WHERE P.SALARY > (SELECT MAX(SALARY) FROM PROGRAMMER WHERE GENDER = 'M')

/*16)Who are the male programmers


earning below the AVG salary of Female Programmers?*/
SELECT
S.STUDENT_NAME,
P.SALARY
FROM STUDIES S INNER JOIN PROGRAMMER P ON S.Student_id = P.P_ID
WHERE P.SALARY < (SELECT AVG(SALARY) FROM PROGRAMMER WHERE GENDER = 'F')
AND P.GENDER = 'M';

/*17) Display the language used by each programmer to develop the


Highest Selling and Lowest-selling package.*/
SELECT Student_id, DEV_IN FROM SOFTWARE
WHERE SOLD IN (SELECT MAX(SOLD) FROM SOFTWARE)
GROUP BY Student_id, DEV_IN
UNION
SELECT STUDENT_ID, DEV_IN FROM SOFTWARE
WHERE SOLD IN (SELECT MIN(SOLD) FROM SOFTWARE)
GROUP BY Student_id, DEV_IN;
/*18) Display the names of the packages,
which have sold less than the AVG number of copies*/
SELECT * FROM SOFTWARE
WHERE SOLD < (SELECT AVG(SOLD) FROM SOFTWARE);

/*19) Which is the costliest package developed in PASCAL.*/


SELECT TITLE, DEV_IN, SCOST FROM SOFTWARE
WHERE SCOST IN (SELECT MAX(SCOST) FROM SOFTWARE WHERE DEV_IN = 'PASCAL');

/*20) How many copies of the package that has the


least difference between development and selling cost were sold.*/
SELECT TITLE, SOLD FROM SOFTWARE
WHERE TITLE = (SELECT TITLE FROM SOFTWARE
WHERE (DCOST-SCOST) = (SELECT MIN(DCOST-SCOST) FROM SOFTWARE));

/*21)Which language has been used to develop the package,


which has the highest sales amount?*/
SELECT * FROM SOFTWARE;
SELECT TITLE, DEV_IN, SCOST, SOLD, (SCOST * SOLD) AS SALES_AMOUNT
FROM SOFTWARE
WHERE TITLE = (SELECT TITLE FROM SOFTWARE
WHERE (SCOST*SOLD) = (SELECT MAX(SCOST*SOLD) FROM SOFTWARE));

/*22)Who Developed the Package that has sold the least number of copies?*/
SELECT STUDENT_ID, TITLE, SOLD FROM SOFTWARE
WHERE SOLD IN (SELECT MIN(SOLD) FROM SOFTWARE);

/*23)Display the names of the courses


whose fees are within 1000 (+ or -) of the Average Fee*/
SELECT * FROM STUDIES;
SELECT AVG(COST) FROM STUDIES;

SELECT COURSE, COST FROM STUDIES


WHERE COST < (SELECT AVG(COST)+1000 FROM STUDIES)
AND COST > (SELECT AVG(COST)-1000 FROM STUDIES);

/*24)Display the name of the Institute and Course,


which has below AVG course fee.*/
SELECT COURSE, STUDENT_PLACE, COST FROM STUDIES
WHERE COST < (SELECT AVG(COST) FROM STUDIES);

/*25) Which Institute conducts costliest course.*/


SELECT STUDENT_PLACE, COURSE, COST FROM STUDIES
WHERE COST = (SELECT MAX(COST) FROM STUDIES);

/*26) What is the Costliest course?*/


SELECT COURSE, STUDENT_PLACE, COST FROM STUDIES
WHERE COST = (SELECT MAX(COST) FROM STUDIES);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy