SQL Questions
SQL Questions
1 Database Structure
(1)
SELECT ID number
FROM PRODUCTS
FROM PRODUCTS
3) Complete the SQL script to display the prices of all the products.
SELECT …………………………
4) Complete the SQL script to display the ID number and name of all the products.
FROM PRODUCTS
5) Complete the SQL scripts to display the Name, Cost and Quantity in stock for all items.
………………………… PRODUCTS
SELECT … FROM … WHERE
FROM MARKS
FROM MARKS
3) Complete the SQL script to display the Test name, percentage and grade when the percentage is more than
50.
FROM …………………………
………………………… MARKS
5) Complete the SQL script to display the student ID, test name and percentage where the percentage is less
than or equal to 25.
………………………… …………………………
FROM WEATHER
FROM WEATHER
FROM WEATHER
4) Complete the SQL script to display the time when the date 12/12/2019 and the humidity is more than 50.
SELECT …………………………
FROM…………………………
FROM WEATHER
Practice
1a) Complete the SQL script to return the name of all the product in the store.
SELECT…………………………
FROM …………………………
1b) Identify the values that will be returned from your query in 1a.
2a) Complete the SQL script to return the name of all products where an order for more products
have been made.
SELECT …………………………
FROM …………………………
2b) Identify the values that will be returned from your query in 2a.
3a) Complete the SQL script to return the product barcode, color and size where the quantity in stock is less
than 10 and an order for more products has not been made.
FROM …………………………
3b) Identify the values that will be returned from your query in 3a.
ORDER BY
FROM WEATHER
ORDER BY Temperature
FROM WEATHER
3) Complete the SQL script to display the date, wind speed and humidity in ascending order of wind speed.
…………………………WEATHER
4) Complete the SQL script to display the date, time and temperature, in descending order of humidity.
FROM WEATHER
FROM …………………………
FROM PRODUCTS
FROM PRODUCTS
FROM PRODUCTS
FROM PRODUCTS
These questions will need your shop database table from Programming Task 9.
Practice
1a) Complete the SQL script to return the name of all the products in the store in descending order of quantity
in stock.
SELECT …………………………
FROM …………………………
ORDER BY …………………………
1b) Identify the values that will be returned from your query in la.
2a) Complete the SQL script to return the total cost of all products.
FROM …………………………
2b) Identify the values that will be returned from your query in 2a.
3a) Complete the SQL script to return how many items have been ordered for more products.
FROM …………………………
3b) Identify the values that will be returned from your query in 3a.
4) Complete the SQL script to return how many items are red, and have more than 100 in stock, in ascending
order by the number in stock.
FROM …………………………
………………………… …………………………
Questions
FROM ORDERS
FROM ORDERS
FROM ORDERS
FROM ORDERS
SELECT………………………… (FirstName)
FROM ORDERS
6) Complete the SQL script to calculate the total cost of orders where 5 or more items have been ordered.
SELECT………………………… (TotalCost)
FROM ORDERS
7) Complete the SQL script to calculate how many orders cost more than 50.00.
FROM …………………………
• Boolean
• Real
• Date / time
• Text
3) A cinema stores data about the films it is showing. It stores the screen number (for example, 1), the film (for
example, The Dark), the date and time of the showing, the number of seats sold (e.g. 150). Define the single-table
database for the cinema by identifying the fields, data types, and primary key for the table.
4) A hairdresser uses a database, APPOINTMENTS, to store upcoming appointments. Part of this database is
shown:
Customer Customer
Appointment ID Date Time Employee ID Appointment type
first name last name
12 1/2/2020 14:00 JP James Smith Cut
13 1/2/2020 14:30 AD Ajay Gupta Cut and dry
14 1/2/2020 16:00 AD Eka Loke Colour
15 1/2/2020 9:45 JP Keanu Kawai Cut and dry
16 2/2/2020 11:15 JP Ariana Wang Cut
17 2/2/2020 12:30 AD Osandi Bandara Colour
c) State what is meant by a primary key, and identify the primary key in the table APPOINTMENTS.\
FROM APPOINTMENTS
e) Identify the output from this SQL script.
FROM APPOINTMENTS
FROM APPOINTMENTS
g) Complete the SQL script to return the number of appointments JP has on 1/2/2020.
………………………… APPOINTMENTS
5) A single-table database, SALES, store details of people who bought books online.
a) Identify the most appropriate data types for the following fields:
• Sales ID
• Date
• Customer ID
• Quantity bought
• Total Cost
b) Give the result from the following SQL script:
FROM SALES
c) Complete the following SQL script to return the customer ID and total cost of each order where more than 1
book were ordered.
FROM …………………………
FROM SALES
e) Complete the following SQL script to calculate the total number of books sold on 4/4/2020.
………………………… SALES
f) Complete the following SQL script to calculate the total cost of all the orders.
………………………… …………………………