0% found this document useful (0 votes)
69 views

Module 5 Temporary Tables Assignment

The document contains SQL queries to analyze data about software developed, programmers, courses, and institutes. It finds details of software by male programmers from the institute with most programmers, identifies popular programming languages and months programmers were hired, determines the year with most programmer births, and analyzes the programmer, course, institute, and language with the most records. The queries return aggregated data using common table expressions to filter on maximum counts or averages across different groupings in the tables.

Uploaded by

Vishnu Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

Module 5 Temporary Tables Assignment

The document contains SQL queries to analyze data about software developed, programmers, courses, and institutes. It finds details of software by male programmers from the institute with most programmers, identifies popular programming languages and months programmers were hired, determines the year with most programmer births, and analyzes the programmer, course, institute, and language with the most records. The queries return aggregated data using common table expressions to filter on maximum counts or averages across different groupings in the tables.

Uploaded by

Vishnu Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

USE JARVIS;

/*1) Display the details of the software developed in DBASE by Male Programmers,
who belong to the institute in which most number of Programmer*/
WITH CTE AS
(
SELECT STUDENT_PLACE, COUNT(STUDENT_PLACE) AS TOTAL FROM STUDIES
GROUP BY Student_place
)
SELECT
SO.TITLE,
SO.DEV_IN,
SO.STUDENT_NAME,
S.STUDENT_PLACE,
P.GENDER,
SO.SCOST,
SO.DCOST,
SO.SOLD
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 = (SELECT STUDENT_PLACE FROM CTE WHERE
STUDENT_PLACE = (SELECT STUDENT_PLACE FROM CTE
WHERE TOTAL = (SELECT MAX(TOTAL) FROM CTE))
AND GENDER IN (SELECT GENDER FROM PROGRAMMER WHERE GENDER = 'M')
AND DEV_IN IN (SELECT DEV_IN FROM PROGRAMMER WHERE DEV_IN = 'DBASE'));

/*2) In which language are most of the programmer’s proficient*/


WITH CTE AS
(
SELECT PROF1, COUNT(PROF1) AS TOTAL FROM PROGRAMMER
GROUP BY PROF1
)
SELECT PROF1 FROM CTE
WHERE TOTAL = (SELECT MAX(TOTAL) FROM CTE);

WITH CTE1 AS
(
SELECT PROF2, COUNT(PROF2) AS TOTAL FROM PROGRAMMER
GROUP BY PROF2
)
SELECT PROF2 FROM CTE1
WHERE TOTAL = (SELECT MAX(TOTAL) FROM CTE1);

/*3) In which month did the most number of programmers join*/


SELECT * FROM PROGRAMMER;

WITH CTE AS
(
SELECT MONTH(DOJ) AS MONTH, ROW_NUMBER()
OVER(PARTITION BY MONTH(DOJ) ORDER BY MONTH(DOJ) DESC) AS ROWNUMBER FROM PROGRAMMER
)
SELECT MONTH FROM CTE WHERE ROWNUMBER IN (SELECT MAX(ROWNUMBER) FROM CTE);

WITH CTE AS
(
SELECT MONTH(DOJ) AS MONTH, COUNT(MONTH(DOJ)) AS TOTAL FROM PROGRAMMER
GROUP BY MONTH(DOJ)
)
SELECT MONTH FROM CTE WHERE TOTAL IN (SELECT MAX(TOTAL) FROM CTE);
/*4) In which year was the most number of Programmers born.*/
WITH CTE AS
(
SELECT YEAR(DOB) AS YEAR, ROW_NUMBER()
OVER(PARTITION BY YEAR(DOB) ORDER BY YEAR(DOB) DESC) AS ROWNUMBER FROM PROGRAMMER
)
SELECT YEAR FROM CTE WHERE ROWNUMBER IN (SELECT MAX(ROWNUMBER) FROM CTE);

WITH CTE AS
(
SELECT YEAR(DOB) AS YEAR, COUNT(YEAR(DOB)) AS TOTAL FROM PROGRAMMER
GROUP BY YEAR(DOB)
)
SELECT YEAR FROM CTE WHERE TOTAL IN (SELECT MAX(TOTAL) FROM CTE);

/*5) Which programmer has developed the highest number of Packages?*/


WITH CTE AS
(
SELECT STUDENT_NAME, STUDENT_ID, COUNT(*) AS TOTAL FROM SOFTWARE
GROUP BY Student_id, STUDENT_NAME
)
SELECT * FROM CTE WHERE TOTAL IN (SELECT MAX(TOTAL) FROM CTE);

/*6) Which language was used to develop the most number of Packages.*/

WITH CTE AS
(
SELECT DEV_IN, COUNT(DEV_IN) AS TOTAL FROM SOFTWARE
GROUP BY DEV_IN
)
SELECT * FROM CTE WHERE TOTAL IN (SELECT MAX(TOTAL) FROM CTE);

/*7)Which course has below average number of Students?*/


WITH CTE AS
(
SELECT COURSE, COUNT(*) AS TOTAL FROM STUDIES
GROUP BY COURSE
)
SELECT COURSE FROM STUDIES
GROUP BY COURSE
HAVING COUNT(*) IN (SELECT AVG(TOTAL) FROM CTE
GROUP BY COURSE);

/*8) Which course has been done by the most of the Students?*/
WITH CTE AS
(
SELECT COURSE, COUNT(*) AS TOTAL FROM STUDIES
GROUP BY COURSE
)
SELECT * FROM CTE WHERE TOTAL IN (SELECT MAX(TOTAL) FROM CTE);

/*9) Which Institute has the most number of Students*/

WITH CTE AS
(
SELECT STUDENT_PLACE, COUNT(*) AS TOTAL FROM STUDIES
GROUP BY STUDENT_PLACE
)
SELECT * FROM CTE WHERE TOTAL IN (SELECT MAX(TOTAL) FROM CTE);

/*10) Who is the Above Programmer Referred in 50?*/

/*11) Display the names of the highest paid programmers for each Language.*/
SELECT STUDENT_NAME, SALARY, PROF1 FROM
(
SELECT STUDENT_NAME, SALARY, PROF1, ROW_NUMBER()
OVER (PARTITION BY PROF1 ORDER BY SALARY DESC) AS ROWNUMBER FROM PROGRAMMER
) SUB
WHERE ROWNUMBER = 1;

You might also like