From 65bfcb3f54719355c83dc2462d36d99fe0ad471f Mon Sep 17 00:00:00 2001 From: Aadit Agrawal Date: Tue, 28 Jan 2025 14:28:41 +0530 Subject: [PATCH] Update DBMS/SQL/Week4/writeup.md --- DBMS/SQL/Week4/writeup.md | 77 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/DBMS/SQL/Week4/writeup.md b/DBMS/SQL/Week4/writeup.md index 745b45d..51a6da5 100644 --- a/DBMS/SQL/Week4/writeup.md +++ b/DBMS/SQL/Week4/writeup.md @@ -1 +1,76 @@ -## Lab 4 - OracleDB \ No newline at end of file +## Lab 4 - OracleDB + +### Verifying the existence of the previous labs' DB. +```sql +SQL> select table_name from user_tables; + +TABLE_NAME +-------------------------------------------------------------------------------- +ACCIDENT +CAR +OWNS +PARTICIPATED +PERSON +``` + +### Q1. Find the total number of people who owned cars that were involved in accidents in 2008. + +Ans. + +Modifying the table to add required entry from 2008. +```sql + +SQL> select * from accident; + +REPORT_NUMBER ACCD_DATE LOCATION +------------- --------- -------------------------------------------------- + 1 01-JAN-24 Delhi India + 3 29-FEB-24 India + 5 31-MAR-00 Gujrat India + 12 17-JUL-00 karnataka India + 10 01-JAN-08 Manipal India + +SQL> update accident set ACCD_DATE='01-Jan-2008' where REPORT_NUMBER=1 + 2 ; + +1 row updated. + +SQL> select * from accident; + +REPORT_NUMBER ACCD_DATE LOCATION +------------- --------- -------------------------------------------------- + 1 01-JAN-08 Delhi India + 3 29-FEB-24 India + 5 31-MAR-00 Gujrat India + 12 17-JUL-00 karnataka India + 10 01-JAN-08 Manipal India +``` + + +```sql +SQL> select count(distinct Driver_ID#) from participated natural join accident where extract(year from accd_date)=2008; + +COUNT(DISTINCTDRIVER_ID#) +------------------------- + 1 +``` + +### Q2. Find the number of accidents in which cars belonging to a specific model were involved. +```sql +SQL> select * from car; + +REGNO MODEL YEAR +-------------------- ------------------------------ ---------- +ABCD0001 Celtos 3 +EFGH2001 Ferrari 32 +DSDS0001 Urus 5 +ABCD4001 Honda City 1 +HFSP5601 mini cooper 7 + +SQL> select count(distinct driver_id#) from car natural join participated where model like 'Urus'; + +COUNT(DISTINCTDRIVER_ID#) +------------------------- + 1 +``` +