SQL Problems and Solutions
SQL Problems and Solutions
SQL Problems and Solutions
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 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
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)