Professional Documents
Culture Documents
SQL Practice QuestionsXII
SQL Practice QuestionsXII
Staff
Registration
9. For each branch, list the numbers and names of staff who manage properties,
including the city in which the branch is located and the properties that the staff
manage.
10. List the clients who have viewed a property.
11. Find the list of all cities where there is both a branch office and a property
12. Give all managers 5% increase to their salary
13. Delete all viewings that belong to property with property number PG4.
Assignment II
Given the following table definitions:
message (message_id, subject, body)
sent_to(message_id, email, senddate)
customer (email, name, family_size, address)
For each case below, fill in the blanks such that the SQL queries correspond to the
English language queries stated.
1- Find the names and emails of all customers who have sent the message with
subject Happy New Year
select _customer.email, name___
from message, sent_to, customer
where _subject=Happy New Year AND
message.message_id=sent_to.message_id AND
sent_to.email=customer.email
2- Find the names and common addresses of all pairs of customers who claim to
have a famlily size 2 and and have the same address.
select C1.name, _C2.name___, C1.address
from _customer C1, customer C2
where _c1.name<>c2.name___ AND, _c1.family_size=2_______ AND
C2.family_size=2 AND _c1.address=c2.address___
3- Find the names of all customers and their family size whose family size is at
least 50% more than the average family size. Sort the results by family size.
from _customer_________average_size
where _family_size >= 1.5* a_size ________________
order by _family_size___________
4- Find all customers each having a family size different from the total number
of customers having the same address as him or her.
create view address_and_count (address, count)
select address, count *
from _customer______________
group by _address______________
select C.name
from_customer C, address_and_count A
where C.address=A.address AND _family_size<>count____
Assignment - III
Consider the following relation table for an airline database.
customer(id, name, age, gender)
onFlight(id, flightNo, flightDate)
flightInfo(flightNo, fromCity, toCity, startTime, duration)
1. Names of all customers above the age of 10
SELECT _______________name
FROM customer
WHERE ________________ age>10
3. Flights (flightNo, flightDate) on which there are at least two customers, as well as the
number of passengers on the flights
SELECT flightNo, flightDate, count(id) as howMany
FROM onFlight
GROUP BY _____________________ flightNo, flightDate
HAVING _____________________ howMany>1
____________________
customer.id=onFlight.id
AND
____________________ onFlight.flightNo=TK102
___________________
customer.id
onFlight.id
AND
8. The most popular destination (i.e. the city which received the most number of
travellers)
WITH city_tourists(toCity,HowMany) AS
SELECT toCity, count(*)
FROM onFlight natural inner join flightInfo
GROUP BY toCity
WITH mostTourist(HowMany) AS
SELECT ___________________ max(HowMany)
FROM ___________________ city_tourists
SELECT toCity
FROM ______________________________ city_tourists, mostTourist
WHERE
_____________________________
city_tourists.HowMany
mostTourist.HowMany
9. How many passengers ever flew to Istanbul? If somebody travelled to Istanbul more
than one time, only one of those visits should be counted.
SELECT ___________________count (distinct id)
FROM onFlight natural inner join flightInfo
WHERE to_city = Istanbul