Query formulation with SQL - Musawer Sadeq
Query formulation with SQL - Musawer Sadeq
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.
sql
SELECT StudentID, FirstName, LastName, Major
FROM Students
WHERE Major = 'Computer Science';
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.
sql
SELECT Major, COUNT(*) AS TotalStudents
FROM Students
GROUP BY Major;
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.