0% found this document useful (0 votes)
132 views

SQL Practice Questions

The document provides example SQL practice questions related to different database schemas including: 1. A schema for branches, staff, properties for rent, clients, private owners, viewings, and registrations. Questions involve listing addresses, staff details, properties viewed, staff salaries, etc. 2. A schema for messages, customers, and questions involve finding customer details based on messages, common customer addresses, and family sizes. 3. A schema for an airline database including customers, flights, and flight details. Questions involve listing customer names by age, flights with multiple customers, passenger names on specific flights, non-flying customers, and popular destinations.

Uploaded by

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

SQL Practice Questions

The document provides example SQL practice questions related to different database schemas including: 1. A schema for branches, staff, properties for rent, clients, private owners, viewings, and registrations. Questions involve listing addresses, staff details, properties viewed, staff salaries, etc. 2. A schema for messages, customers, and questions involve finding customer details based on messages, common customer addresses, and family sizes. 3. A schema for an airline database including customers, flights, and flight details. Questions involve listing customer names by age, flights with multiple customers, passenger names on specific flights, non-flying customers, and popular destinations.

Uploaded by

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

SQL Practice Questions

Consider the following schema definitions:


Branch (branchNo, street, city, postcode)
Staff (staffNo, fName,lName, position, sex, DOB, salary, branchNo)
PropertyforRent (propertyNo, street, city, postcode, type, rooms, rent, ownerNo,
staffNo, branchNo)
Client (clientNo, fName, lName, telNo, prefType, maxRent)
PrivateOwner (ownerNo, fName, lName, address, telNo)
Viewing (clientNo, propertyNo, viewDate, comment)
Registration (clientNo, branchNo, staffNo, dateJoined)

1. List the address of all branch offices in London or Bristol.


2. List the staff with a salary between $10000 and $30000.
3. List the staff in descending order of salary.
4. Find the number of different properties viewed in April 2004.
5. Find the minimum, maximum and average staff 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.
7. List the staff who work in the branch whose stree adress is ‘163 Main Street’
8. Find all staff whose salary is larger than the salary of every staff member at branch
with branchNo 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.
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.
Given the following schema definitions:

message (message_id, subject, body)


sent_to(message_id, email, senddate)
customer (email, name, family_size, address)

1. Find the names and emails of all customers who have sent the message with
subject “Happy New Year”
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.
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.
4. Find all customers each having a family size different from the total number of
customers having the same address as him or her.

Consider the following relation schema 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.

2. Flights (flightNo, flightDate) on which there are at least two customers

3. Flights (flightNo, flightDate) on which there are at least two customers, as well as

the number of passengers on the flights

4. Names of passengers who flew on flight “TK102” at least once

5. Names of customers who never flew on any flight

6. Names of customers who flew on the same flight as Mr. Joe

7. The number of passengers on flight “TK101” on “1/2/1999”


8. The most popular destination (i.e. the city which received the most number of

travellers)

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.

You might also like