77 lines
2.1 KiB
Markdown
77 lines
2.1 KiB
Markdown
## 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
|
|
```
|
|
|