0% found this document useful (0 votes)
1K views

SQL Problems and Solutions

The document contains instructions for multiple database queries across 3 labs. Lab 1 involves finding employee names, addresses, salaries, and other attributes from different companies. Lab 2 focuses on analyzing companies based on number of employees, payroll, and average salaries. Lab 3 contains queries related to accidents, cars, and people involved in accidents for a specific year.

Uploaded by

mansha99
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

SQL Problems and Solutions

The document contains instructions for multiple database queries across 3 labs. Lab 1 involves finding employee names, addresses, salaries, and other attributes from different companies. Lab 2 focuses on analyzing companies based on number of employees, payroll, and average salaries. Lab 3 contains queries related to accidents, cars, and people involved in accidents for a specific year.

Uploaded by

mansha99
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Lab-1

Find the names of all employees who work for First Bank Corporation.

Find the names and cities of residence of all employees who work for First Bank Corporation.

Find the names, street address, and cities of residence of all employees who work for First Bank Corporation and earn more than $10,000 per annum.

Find the names of all employees in this database who live in the same city as the company for which they work.

Find the names of all employees who live in the same city and on the same street as do their managers.

Find the names of all employees in this database who do not work for First Bank Corporation. Find the names of all employees who earn more than every employee of Small Bank Corporation.

Assume the companies may be located in several cities. Find all companies located in every city in which Small Bank Corporation is located.

Lab-2

Find the company with the most employees.

Find the company with the smallest payroll.

Find those companies whose employees earn a higher salary, on average, than the average salary at First Bank Corporation.

Lab-3

Find the total number of people who owned cars that were involved in ac- cidents in 1989.

Select count (distinct name) from accident, participated, person where accident.report-number = participated.report-number and participated.driver-id = person.driver-id and date between date 1989-00-00 and date 1989-12-31

Find the number of accidents in which the cars belonging to John Smith were involved.

select count (distinct *) from accident!where exists (select *!from participated, person!where participated.driver-id = person.driver-id and person.name = John Smith!and accident.report-number = participated.report-number)

Add a new accident to the database; assume any values for required attributes.
insert into accident values (4007, 2001-09-01, Berkeley) insert into participated! select o.driver-id, c.license, 4007, 3000!from person p, owns o, car c!where p.name = Jones and p.driver-id = o.driver-id and o.license = c.license and c.model = Toyota

Delete the Mazda belonging to John Smith.


delete car!where model = Mazda and license in !(select license!from person p, owns o!where p.name = John Smith and p.driver-id = o.driver-id) !

Update the damage amount for the car with license numberAABB2000 in the accident with report number AR2197 to $3000.
!update participated!set damage-amount = 3000!where report-number = AR2197 and driver-id in !(select driver-id!from owns!where license = AABB2000)

You might also like