SQL Practice Questions
SQL Practice Questions
An instance of the above schemas is given in the last page of the examination. (You may
detach and use it if necessary)
For each case below, fill in the blanks such that the SQL queries correspond to the
English language queries stated. Each blank is worth 2 points.
SELECT _______*_______
FROM ___branch______
WHERE city=’London’ _OR city=’bristol’______
SELECT staff_No
FROM Staff
WHERE __salary between 10000 AND 30000________________
3. List the staff in descending order of salary.
6. For each branch office with more than one member of staff, find the number of
staff working in each branch and the sum of their salaries.
8. Find all staff whose salary is larger than the salary of every staff member at branch
with branchNo B003.
SELECT staffNo, fName, lName, position, salary
FROM Staff
WHERE _salary > ALL__________(SELECT salary
FROM __staff_______________
WHERE brancNo=’B003’)
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.
(SELECT city
FROM Branch)
___INTERSECT________
(SELECT city
FROM _PropertyforRent__)
UPDATE __staff_____________
SET __salary=salary*1.05
WHERE position=’Manager’
13. Delete all viewings that belong to property with property number PG4.
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” (2 pts)
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. (7 pts)
4- Find all customers each having a family size different from the total number
of customers having the same address as him or her. (6 pts)
select C.name
from_customer C, address_and_count A
where C.address=A.address AND _family_size<>count____
Consider the following relation schema for an airline database.
customer(id, name, age, gender)
onFlight(id, flightNo, flightDate)
flightInfo(flightNo, fromCity, toCity, startTime, duration)
Assume all flights take place every day. Fill in the missing slots in each ofd the queries
below. Each slot is worth 2 pts, except the first one, which is worth 1 pt.
SELECT _______________name
FROM customer
3. Flights (flightNo, flightDate) on which there are at least two customers, as well as the
FROM onFlight
SELECT name
____________________ onFlight.flightNo=”TK102”
SELECT name
WITH joeFlight(flightNo) AS
SELECT flightNo
SELECT name
travellers)
WITH city_tourists(toCity,HowMany) AS
GROUP BY toCity
WITH mostTourist(HowMany) AS
SELECT toCity
mostTourist.HowMany
9. How many passengers ever flew to Istanbul? If somebody travelled to Istanbul more