0% found this document useful (0 votes)
14 views2 pages

Query formulation with SQL - Musawer Sadeq

The document contains SQL queries for various tasks related to student and faculty data management. It includes retrieving information about juniors and seniors, students majoring in Computer Science, listing students with their advisors, counting students by major, and finding departments with average faculty salaries over $60,000. Each query is accompanied by a brief explanation of its purpose.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Query formulation with SQL - Musawer Sadeq

The document contains SQL queries for various tasks related to student and faculty data management. It includes retrieving information about juniors and seniors, students majoring in Computer Science, listing students with their advisors, counting students by major, and finding departments with average faculty salaries over $60,000. Each query is accompanied by a brief explanation of its purpose.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Name: Musawer Sadeq Period: 7 Date: 2/18/2025

1. Find all juniors and seniors, but only show their ID, first name, last name, and class.

sql
SELECT StudentID, FirstName, LastName, StdClass
FROM Students
WHERE StdClass IN ('JR', 'SR');

This grabs only juniors and seniors from the list of students.

2. Show students who are majoring in Computer Science.

sql
SELECT StudentID, FirstName, LastName, Major
FROM Students
WHERE Major = 'Computer Science';

This pulls only the students whose major is Computer Science.

3. List students with their advisor's name.

sql
SELECT Students.FirstName, Students.LastName, Faculty.FacFirstName,
Faculty.FacLastName
FROM Students
JOIN Faculty ON Students.AdvisorID = Faculty.FacSSN;

This links the Students table with the Faculty table, so we can see who advises who.

4. Count how many students are in each major.

sql
SELECT Major, COUNT(*) AS TotalStudents
FROM Students
GROUP BY Major;

This counts how many students are in each major.


5. Find departments where the average faculty salary is over $60,000.

sql
SELECT DeptName, AVG(FacSalary) AS AvgSalary
FROM Faculty
GROUP BY DeptName
HAVING AVG(FacSalary) > 60000;

This checks each department and only shows the ones where faculty make more than $60K on
average.

You might also like