Question
Write Sql queries that answer the question below (one nested query per question) in the ANSI-style join. The query answers must not contain duplicates, but
Write Sql queries that answer the question below (one nested query per question) in the ANSI-style join. The query answers must not contain duplicates, but you should use the SQL keyword distinct only when necessary.
1. Retrieve the names of all faculty members who made more than Grace Harper.
2. Find the names of the faculty members whose salary is higher than the average salary of all faculty members.
3. For each department, retrieve the names of the faculty members whose salary is higher than his/her department average salary.
4. Retrieve the ids, names, and addresses of all students who have the same advisor as Alan Turing. Each student has at most one advisor.
5. Retrieve the ids and names o every student who has a major in the same department as Alan Turing. Each student could have more than one major.
-- defining relations CREATE TABLE Departments ( deptName VARCHAR (30) building VARCHAR (45) budget FLOAT (8,2), PRIMARY KEY (deptName)) 1 CREATE TABLE Faculty CHAR (9), nameVARCHAR (30), office VARCHAR (45), phone CHAR (12), DATE 3sn CHAR (11), email VARCHAR (40) deptName VARCHAR (30) salary FLOAT 10, 2), PRIMARY KEY (id), FOREIGN KEY (deptName) REFERENCES Departments (deptName)) CREATE TABLE Students ( CHAR (9), nameVARCHAR (30), address VARCHAR (45), DATE email VARCHAR (40) advisor CHAR (9), gpa FLOAT (4, 3), PRIMARY KEY (id), FOREIGN KEY (advisor) REFERENCES Faculty (id)); -- defining relations CREATE TABLE Departments ( deptName VARCHAR (30) building VARCHAR (45) budget FLOAT (8,2), PRIMARY KEY (deptName)) 1 CREATE TABLE Faculty CHAR (9), nameVARCHAR (30), office VARCHAR (45), phone CHAR (12), DATE 3sn CHAR (11), email VARCHAR (40) deptName VARCHAR (30) salary FLOAT 10, 2), PRIMARY KEY (id), FOREIGN KEY (deptName) REFERENCES Departments (deptName)) CREATE TABLE Students ( CHAR (9), nameVARCHAR (30), address VARCHAR (45), DATE email VARCHAR (40) advisor CHAR (9), gpa FLOAT (4, 3), PRIMARY KEY (id), FOREIGN KEY (advisor) REFERENCES Faculty (id))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started