0% found this document useful (0 votes)
209 views4 pages

Database System - NUCES-FAST - Assignment # 3 - Solution

Uploaded by

k224818
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)
209 views4 pages

Database System - NUCES-FAST - Assignment # 3 - Solution

Uploaded by

k224818
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

22K-4818 DB-BSE-5B-A3 MUSTAFA MASOOD

Q1.

1. Find the names of students enrolled in 'Database Systems':


π sname (σ cname=' DatabaseSystems ' (Courses )⋈Courses .cid =Enrollments .cid Enrollments⋈ Enrollments .sid=Students . sid Students)

2. Find student IDs of students with a grade above 90:


π sid ( σ grade>90 ( Enrollments ))

3. Find the names of students who have never taken a course with
less than 3 credits:
π sname ( Students )−π sname ( σ credits<3 ( Courses ) ⋈Courses .cid= Enrollments .cid Enrollments⋈ Enrollments .sid=Students . sid Students )

4. Find the IDs of students who have taken all courses:


π sid (Students)÷ π cid (Courses)

5. Find the names of students who have taken at least two courses:
π sname (σ count ≥2 ​(sname I count (cid)(Enrollments⋈ Students. sid=Enrollments .sid Students )))

6. Find the names of students who have taken all courses in the
Spring semester:
π sname (Students ⋈Students . sid= Enrollments. sid (π cid (σ semester=' Spring ' ​(Enrollments) )÷ π cid (Enrollments)))

7. Find the student IDs of students whose grade is higher than some
student named 'Aliyan':
π sid (σ grade> π grade ​( σ sname ='Aliyan ' (Students ))
(Students))

8. Find the student IDs of students whose grade is higher than every
student named 'huzaifa’:

22K-4818 DB-BSE-5B-A3 MUSTAFA MASOOD


22K-4818 DB-BSE-5B-A3 MUSTAFA MASOOD

π sid ( σ grade>( I MAX (grade )( σ ( Students ) ))


( Students ) )

9. Find the names of students who have enrolled in courses worth


' '
sname¿ Huzaif a

exactly 4 credits:
π sname ( σ credits=4 (Courses ) ⋈Courses. cid= Enrollments. cid ⋈ ​Enrollments ⋈ Enrollments. sid=Students .sid Students )

10. Find the student IDs of students who have taken the course
with the most credits:
π sid (Enrollments ⋈Enrollments .cid =Courses. cid (σ credits=I MAX (credits ) (Courses)))

Q2.

1. π_title (σ_inColor = 0 ∧ year > 1970 (Movie))


Textual Meaning: This retrieves titles of movies that are not in color
and were released after 1970.

SELECT title FROM Movie WHERE inColor = 0 AND year > 1970;

2. π_title (σ_(studioName = 'MGM' ∧ year > 1970) ∨ length < 90


(Movie))
Textual Meaning: This retrieves titles of movies produced by MGM
after 1970 or any movie with a runtime shorter than 90 minutes.

SELECT title FROM Movie WHERE (studioName = 'MGM' AND year >
1970) OR length < 90;

3. π_title, length (σ_studioName = 'Disney' ∧ year = 1990 (Movie))


Textual Meaning: This returns the title and length of movies
produced by Disney in 1990.

SELECT title, length FROM Movie WHERE studioName = 'Disney'


AND year = 1990;

4. π_title, length/60 (σ_studioName = 'Disney' ∧ year = 1990


(Movie))
Textual Meaning: This returns the title and duration (in hours) of
Disney movies from 1990.

SELECT title, length/60 AS duration_in_hours FROM Movie WHERE

22K-4818 DB-BSE-5B-A3 MUSTAFA MASOOD


22K-4818 DB-BSE-5B-A3 MUSTAFA MASOOD

studioName = 'Disney' AND year = 1990;

5. π_producerC (Movie ⨝ StarsIn ⨝ σ_starName = 'Harrison Ford'


(StarsIn))
Textual Meaning: This retrieves producer codes for movies that
feature Harrison Ford.

SELECT DISTINCT producerC FROM Movie JOIN StarsIn ON Movie.title


= StarsIn.movieTitle AND Movie.year = StarsIn.movieYear WHERE
starName = 'Harrison Ford';

6. π_Star.name, Exec.name (σ_Star.address = Exec.address


(MovieStar ⨝ MovieExec))
Textual Meaning: This lists pairs of MovieStar and MovieExec who
share the same address.

SELECT MovieStar.name AS StarName, MovieExec.name AS


ExecName FROM MovieStar JOIN MovieExec ON MovieStar.address =
MovieExec.address;

7. π_producerC (σ_title ≠ 'Star Wars' (Movie))


Textual Meaning: This retrieves producer codes for all movies except
"Star Wars."

SELECT DISTINCT producerC FROM Movie WHERE title != 'Star


Wars';

8. π_producerC (σ_studioName = 'Disney' (Movie)) ∩ π_producerC


(σ_studioName = 'MGM' (Movie))
Textual Meaning: This returns producer codes for producers who
have worked with both Disney and MGM.

SELECT producerC FROM Movie WHERE studioName = 'Disney'


INTERSECT SELECT producerC FROM Movie WHERE studioName =
'MGM';

9. π_title (Movie) - π_title (Movie ⨝ MovieExec)


Textual Meaning: This retrieves titles of movies that do not have an
associated MovieExec.

SELECT title FROM Movie WHERE title NOT IN (SELECT title FROM
Movie JOIN MovieExec ON Movie.producerC = MovieExec.cert);

22K-4818 DB-BSE-5B-A3 MUSTAFA MASOOD


22K-4818 DB-BSE-5B-A3 MUSTAFA MASOOD

S1 = ρ_title1,year1,name1 (StarsIn)
S2 = ρ_title2,year2,name2 (StarsIn)
10.

(S1) ⋈ name1=name2 AND (title1 != title2 OR year1 != year2) (S2)


Textual Meaning: This finds pairs of stars who have acted in different
movies.

SELECT S1.starName AS Star1, S2.starName AS Star2, S1.movieTitle


AS Movie1, S2.movieTitle AS Movie2 FROM StarsIn S1 JOIN StarsIn
S2 ON S1.starName = S2.starName AND (S1.movieTitle !=
S2.movieTitle OR S1.movieYear != S2.movieYear);

22K-4818 DB-BSE-5B-A3 MUSTAFA MASOOD

You might also like