Update DBMS/SQL/Week5/writeup.md

This commit is contained in:
Aadit Agrawal 2025-02-04 16:04:20 +05:30
parent baba02238b
commit 1de09bd5f6

View File

@ -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.
```