30 likes | 135 Views
This document presents a series of SQL queries designed to retrieve data from the "Students" and "Inroll" tables within an academic database, specifically focusing on the Computer Science (CS) department. The first query selects the last and first names of students majoring in CS. The second query finds the maximum grade for courses taken by these students, while the third query retrieves specific student information based on nested conditions related to coursework. The queries demonstrate both straightforward and complex data retrieval techniques.
E N D
1. A plain query SELECT "LastName", "FirstName" FROM "Students" WHERE "Department" = 'CS'; Query Plan: Query plan text: "Seq Scan on "Students" (cost=0.00..12.88 rows=1 width=236)" " Filter: (("Department")::text = 'CS'::text)"
2 A little complex query select I."Cid",max("Grade") from "Inroll" as I, "Students" as S where S."Sid" = I."Sid" And S."Department" = 'CS' group by I."Cid"; Query Plan:
3. Nested Query select "LastName", "Firstname" from "Inroll" as I, "Students" as S where S."Sid" = I."Sid" and I."Cid" = 'CS2223' and I."Sid" in (select "Sid" from "Inroll" where "Cid" = 'CS4432'); Query Plan: