Update DBMS/SQL/Week4/writeup.md
This commit is contained in:
parent
65bfcb3f54
commit
1289cdbd07
@ -56,6 +56,7 @@ COUNT(DISTINCTDRIVER_ID#)
|
||||
```
|
||||
|
||||
### Q2. Find the number of accidents in which cars belonging to a specific model were involved.
|
||||
Ans.
|
||||
```sql
|
||||
SQL> select * from car;
|
||||
|
||||
@ -74,3 +75,28 @@ COUNT(DISTINCTDRIVER_ID#)
|
||||
1
|
||||
```
|
||||
|
||||
### Q3. Produce a listing with header as OWNER_NAME, No. of Accidents, and Total Damage Amount in a descending order on total damage.
|
||||
Ans.
|
||||
```sql
|
||||
SQL> select name as OWNER_NAME,count(distinct DRIVER_ID#),sum(Damage_amount) as total_Damage from person natural join participated group by(name) order by(TOTAL_DAMAGE) DESC;
|
||||
|
||||
OWNER_NAME COUNT(DISTINCTDRIVER_ID#) TOTAL_DAMAGE
|
||||
---------- ------------------------- ------------
|
||||
Amogh 1 26500
|
||||
Rohan 1 10000
|
||||
Ramesh 1 150
|
||||
```
|
||||
|
||||
### Q4. List the Owners who made more than 2 accidents in a year.
|
||||
Ans.
|
||||
```sql
|
||||
SQL> insert into participated values(1236,'DSDS0001',99,100000000);
|
||||
|
||||
1 row created.
|
||||
|
||||
SQL> select name,extract(year from accd_date) as year,count(report_number) as total_accidents from person natural join participated join accident using (report_number) group by(name,extract(year from accd_date)) having count(report_number)>=2;
|
||||
|
||||
NAME YEAR TOTAL_ACCIDENTS
|
||||
---------- ---------- ---------------
|
||||
Ramesh 2024 2
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user