0% found this document useful (0 votes)
3 views6 pages

Queries From QP

The document outlines SQL queries for three different database schemas: one for a student-faculty-course system, another for a flight booking system, and a third for employment and residency data. It includes queries to retrieve student names based on course enrollment, average faculty salaries by department, flight details, and relationships between passengers and agencies. The document also covers queries related to employees' companies and their locations.

Uploaded by

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

Queries From QP

The document outlines SQL queries for three different database schemas: one for a student-faculty-course system, another for a flight booking system, and a third for employment and residency data. It includes queries to retrieve student names based on course enrollment, average faculty salaries by department, flight details, and relationships between passengers and agencies. The document also covers queries related to employees' companies and their locations.

Uploaded by

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

Database Schema:

 Student(USN, NAME, BRANCH, PERCENTAGE)


 Faculty(FID, FNAME, DEPARTMENT, DESIGNATION, SALARY)
 Course(CID, CNAME, FID)
 Enroll(CID, USN, GRADE)

(i) Retrieve the names of all students enrolled for the course 'CS_54':

SELECT S.NAME

FROM Student S

JOIN Enroll E ON S.USN = E.USN

WHERE E.CID = 'CS_54';

OR

SELECT S.NAME

FROM Student S, Enroll E

WHERE S.USN = E.USN AND E.CID = 'CS_54';

(ii) List all the departments having an average salary of the faculties above Rs.
10,000:

SELECT DEPARTMENT

FROM Faculty

GROUP BY DEPARTMENT
HAVING AVG(SALARY) > 10000;

(iii) List the names of the students enrolled for the course 'CS_51' and having 'B' grade:

SELECT S.NAME

FROM Student S

JOIN Enroll E ON S.USN = E.USN

WHERE E.CID = 'CS_51' AND E.GRADE = 'B';

OR

SELECT S.NAME

FROM Student S, Enroll E

WHERE S.USN = E.USN AND E.CID = 'CS_51' AND E.GRADE = 'B';

Schema:

 Passenger(pid, pname, pgender, pcity)


 Agency(aid, aname, acity)
 Flight(fid, fdate, time, src, dest)
 Booking(pid, aid, fid, fdate)
(i) Get the complete details of all flights to New Delhi:

SELECT *

FROM Flight

WHERE dest = 'New Delhi';

(ii) Find only the flight numbers for passenger with pid 123 for flights to Chennai before
06/11/2020:

SELECT F.fid

FROM Flight F

JOIN Booking B ON F.fid = B.fid AND F.fdate = B.fdate

WHERE B.pid = 123 AND F.dest = 'Chennai' AND F.fdate < '2020-11-06';

OR

SELECT F.fid

FROM Flight F, Booking B

WHERE F.fid = B.fid AND F.fdate = B.fdate

AND B.pid = 123 AND F.dest = 'Chennai' AND F.fdate < '2020-11-06';

(iii) Find the passenger names for those who do not have any bookings in any flights:

SELECT pname

FROM Passenger

WHERE pid NOT IN (SELECT pid FROM Booking);

iv) Get the details of flights that are scheduled on both dates 01/12/2020 and 02/12/2020 at 16:00
hours:

SELECT *

FROM Flight F1

WHERE F1.fdate = '2020-12-01' AND F1.time = '16:00:00'

AND EXISTS (

SELECT *

FROM Flight F2

WHERE F2.fid = F1.fid AND F2.fdate = '2020-12-02' AND F2.time = '16:00:00'

);
(v) Find the details of all male passengers who are associated with Jet agency:

SELECT P.*

FROM Passenger P

JOIN Booking B ON P.pid = B.pid

JOIN Agency A ON B.aid = A.aid

WHERE P.pgender = 'Male' AND A.aname = 'Jet';

OR

SELECT P.*

FROM Passenger P, Booking B, Agency A

WHERE P.pid = B.pid AND B.aid = A.aid

AND P.pgender = 'Male' AND A.aname = 'Jet';

Schema:

 Works(Pname, Cname, Salary)


 Lives(Pname, Street, City)
 LocatedIn(Cname, City)

i) List the names of the people who work for the Company 'Wipro' along with the cities they live
in:

SELECT W.Pname, L.City

FROM Works W

JOIN Lives L ON W.Pname = L.Pname

WHERE W.Cname = 'Wipro';

OR
SELECT W.Pname, L.City

FROM Works W, Lives L

WHERE W.Pname = L.Pname AND W.Cname = 'Wipro';

(ii) Find the names of the persons who do not work for 'Infosys':

SELECT DISTINCT Pname

FROM Works

WHERE Pname NOT IN (

SELECT Pname

FROM Works

WHERE Cname = 'Infosys'

);

(iii) Find the people whose salaries are more than that of all the 'Oracle' employees:

SELECT Pname

FROM Works

WHERE Salary > ALL (

SELECT Salary

FROM Works

WHERE Cname = 'Oracle'

);

(iv) Find the persons who work and live in the same city:

SELECT W.Pname

FROM Works W

JOIN Lives L ON W.Pname = L.Pname

JOIN LocatedIn LI ON W.Cname = LI.Cname

WHERE L.City = LI.City;

OR

SELECT W.Pname

FROM Works W, Lives L, LocatedIn LI


WHERE W.Pname = L.Pname AND W.Cname = LI.Cname AND L.City = LI.City;

(v) Find the names of the companies that are located in every city where the Company Infosys is
located:

SELECT DISTINCT LI1.Cname

FROM LocatedIn LI1

WHERE NOT EXISTS (

SELECT City

FROM LocatedIn

WHERE Cname = 'Infosys'

EXCEPT

SELECT City

FROM LocatedIn LI2

WHERE LI2.Cname = LI1.Cname

);

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