0
7.1kviews
write SQL queries

For the following given database, write SQL queries:

Person (driver_id:#, name, address)

Car (license, model, year)

Accident (reporcino, date, location)

Owns (driver_id:#, license)

Participated (drivercid, car, report_number, damage_amount)

(i) Find the total number of people who owned cars that were involved in accident 2004

(ii) Find the number of accidents in which the cars belonging to "HT" were involved

(iii) Update the damage an, unt for car with license number "Mum2011" in the accident with report number "AR120" to Rs. 4000

1 Answer
1
447views

i. Find the total number of people who owned cars that were involved in accident 2004?

select count (distinct name) 
from accident, participated, person 
where accident.reporcno = participated.report_number 
and participated.drivercid = person.driver_id 
and date between date ’2004-01-01’ and date ’2004-12-31’.

ii. Find the number of accidents in which the cars belonging to "HT" were involved

select count (distinct *) from accident 
where exists
(select * from participated, person 
where participated.drivercid = person.driver_id 
and person.name = ’HT’ 
andaccident.reporcno = participated.report_number)

iii. Update the damage amount for car with license number "Mum2011" in the accident with report number "AR120" to Rs. 4000

update participated 
setdamage_amount = 4000
wherereport_number = “AR120” 
anddrivercid in 
(selectdriver_id from owns 
where license = “Mum2011”)
Please log in to add an answer.