From 1de09bd5f6264a8427cd7426391b3d85a8ebf82f Mon Sep 17 00:00:00 2001 From: Aadit Agrawal Date: Tue, 4 Feb 2025 16:04:20 +0530 Subject: [PATCH] Update DBMS/SQL/Week5/writeup.md --- DBMS/SQL/Week5/writeup.md | 75 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/DBMS/SQL/Week5/writeup.md b/DBMS/SQL/Week5/writeup.md index e578dd7..a4d6c8c 100644 --- a/DBMS/SQL/Week5/writeup.md +++ b/DBMS/SQL/Week5/writeup.md @@ -425,11 +425,65 @@ DEPT ICT ``` - ### Find the students who have enrolled for course of more than one department +```sql +SQL> select name + 2 from student + 3 where regno in( + 4 select regno + 5 from enroll natural join course + 6 group by regno + 7 having count(distinct dept)>1); + +NAME +-------------------- +Aadit +``` + +To create a list, we use + +```sql +SQL> select regno,count(distinct dept) + 2 from enroll natural join course + 3 group by regno; + +REGNO COUNT(DISTINCTDEPT) +-------------------- ------------------- +456 2 +101 1 +890 1 +567 1 +123 1 +789 1 + +6 rows selected. +``` + ### Produce a list of students who are not enrolled. +```sql +SQL> select regno,name + 2 from student + 3 where regno not in( + 4 select regno from enroll); + +REGNO NAME +---------- -------------------- +234 Vansh + +SQL> +SQL> select regno,name + 2 from student + 3 where not exists( + 4 select regno from enroll + 5 where student.regno=enroll.regno); + +REGNO NAME +---------- -------------------- +234 Vansh +``` + ### List the department which adopts all the books from the particular publisher ```sql @@ -548,3 +602,22 @@ Classmate 1 ### List the students who enrolled for all the books adopted by their course +```sql +SQL> select distinct regno + 2 from enroll natural join student + 3 where exists + 4 (select book_isbn + 5 from book_adoption + 6 where book_adoption.course#=enroll.course#); + +REGNO +-------------------- +456 +101 +890 +123 +567 +789 + +6 rows selected. +```