SQL Test Key
SQL Test Key
Using this test you can assess whether you have basic working knowledge of SQL that is prerequisite for attending
Deloitte’s Data Science Academy – Intermediate program. To verify accuracy of your answers, use the key with
correct answers at the end of this document. In case that your success rate will be lower than 75% (i.e., you will
answer correctly less than 30 questions out of 40), you should consider consulting available on-line resources that
will enable you to become more deeply familiarized with SQL. For that purpose, we have provided you for each
question with a link that will bring you to the website that will help you to grasp and practice given SQL concept.
There is no strict time limit for finishing the test, but we suppose that you will be able to finish it in ~20 minutes.
Some of the questions within the test assume that following Customers, Orders, Products and OrderDetails tables
from the Test database are available to you.
Customers table:
Orders table:
Products table:
OrderDetails table:
01
Q1) What SQL statement would you use to create SQL database named Test?
Q2) What SQL statement would you use to remove SQL database named Test?
Q3) Assign individual relationships that one can find in ERD (Entity Relationship Diagram) to their appropriate
descriptions.
Q4) Which kind of relationship best describes relationship between Products (A) and OrderDetails (B) tables?
a)
b)
c)
d)
Q5) Fulfill missing parts in SQL statement below to create Products table.
______________ ________ (
ProductID INT ______________,
ProductName VARCHAR(255),
SupplierID INT,
CategoryID INT,
Unit _____________,
Price _____________
);
Q6) Primary Key is a combination of two types of constraints. Find the correct one in the list below.
Q7) Which field in the Orders table has a role of FOREIGN KEY in relation to Customers table?
a) CustomerID
b) OrderID
c) OrderDate
d) CustomerName
02
Q8) What SQL statement would you use to put a new record into the Orders table?
a) INSERT INTO Orders (OrderID, CustomerID, OrderDate) VALUES (200, 125, '2018-02-05');
b) PUT INTO Orders (OrderID, CustomerID, OrderDate) VALUES (200, 125, '2018-02-05');
c) INSERT VALUES (200, 125, '2018-02-05') INTO Orders (OrderID, CustomerID, OrderDate);
d) PUT VALUES (200, 125, '2018-02-05') INTO Orders (OrderID, CustomerID, OrderDate);
Q9) What SQL statement would you use to modify the existing record of CustomerID to 10 for OrderID #10308 in
the Orders table?
Q10) What SQL statement would you use to delete order with OrderID #10308 from the Orders table?
Q11) What SQL statement would you use to add an Age field to the Customers table?
a) UPDATE TABLE Customers ADD Age INT;
b) ALTER TABLE Customers ADD Age INT;
c) UPDATE TABLE ADD Age INT Customers;
d) ALTER TABLE ADD Age INT Customers;
Q12) What SQL statement would you use to remove Customers table from Test database?
Q13) Fulfill missing parts in SQL statement below to extract all records from Customers table.
_______ _____________________
_______ Customers;
Q14) Fulfill missing parts in SQL statement below to extract CustomerName and Address from Customers table.
_______ _____________________
_______ Customers;
Q15) Fulfill missing parts in SQL statement below to extract all distinct countries from Customers table.
Q16 Fulfill missing parts in SQL statement below to extract all records from Products table that will include only
products with price higher than 20 EUR.
_______ _____________________
_______ Products
_______ Price _________________;
03
Q17) Fulfill missing parts in SQL statement below to extract all records from Customers table that will include only
those customers who have NULL values in Address field.
_______ _____________________
_______ Customers
_______ _____________________;
Q18) Fulfill missing parts in SQL statement below to extract all records from Customers table that will include only
those customers who are from Germany or UK.
_______ _____________________
_______ Customers
_______ Country _______________________________;
Q19) Fulfill missing parts in SQL statement below to extract all records from Customers table that will include only
those customers who are not from USA.
_______ _____________________
_______ Customers
_______ _______ Country _____________;
Q20) Fulfill missing parts in SQL statement below to extract all records from Products table that will include only
those products that are supplied by supplier with SupplierID #1 and that belong to CategoryID #2.
_______ _____________________
_______ Products
_______ _______________ ______ ___________________;
Q21) Fulfill missing parts in SQL statement below to arrange records in Products table according to Price in
descending order.
_______ _____________________
_______ Products
_______ _____________________;
Q22) Fulfill missing parts in SQL statement below to extract the first 50 records from Customers table.
Q23) Fulfill missing parts in SQL statement below to find maximum Price for products listed in Products table.
_______ _____________________
_______ Products;
Q24) What statement will you use to count number of records within Customers table?
Q25) Fulfill missing parts in SQL statement below to find average Price for products listed in Products table.
_______ _____________________
_______ Products;
04
Q26) Fulfill missing parts in SQL statement below to find overal number of ordered products using Quantity field in
OrderDetails table.
_______ _____________________
_______ OrderDetails;
Q27) Fulfill missing parts in SQL statement below to find all customers listed in the Customers table whose name
starts with letter „b“.
_______ _____________________
_______ Customers
_______ CustomerName _________________;
Q28) Fulfill missing parts in SQL statement below to find all customers listed in the Customers table whose name
starts with letter „b“ and ends with letter „o“.
_______ _____________________
_______ Customers
_______ CustomerName _________________;
Q29) Fulfill missing parts in SQL statement below to find all customers listed in the Customers table whose name
has letter „b“ in the second position.
_______ _____________________
_______ Customers
_______ CustomerName _________________;
Q30) Fulfill missing parts in SQL statement below to find all customers listed in the Customers table who live in
Germany, UK, and USA.
_______ _____________________
_______ Customers
_______ _________ ___ (“Germany“, “UK“, “USA“);
Q31) Fulfill missing parts in SQL statement below to find all products listed in the Products table whose price
belongs to range from 5 to 25 EUR, including the begin and end values.
_______ _____________________
_______ Products
_______ Price _________ ___ ____ _________;
Q32) What statement would you use to change temporarily name of the CustomerName field to Customer within
Customer table?
Q33) Fulfill missing parts in SQL statement below to select all orders with existing customer information.
Q34) Fulfill missing parts in SQL statement below to select all customers and any orders they might have.
05
Q35) Fulfill missing parts in SQL statement below to select all customers and any orders they might have.
Q36) Fulfill missing parts in SQL statement below to select all customers and all orders.
Q37) What operator would you use to merge selects from two different tables with the same number of columns in
the same order and with similar data types?
a) JOIN
b) MERGE
c) UNITE
d) UNION
Q38) Fulfill missing parts in SQL statement below to calculate overal Quantity for each ProductID and arrange the
resulting list in descending order according to this new metric.
Q39) Fulfill missing parts in SQL statement below to filter products whose overal Quantity is higher than 100 and
arrange the resulting list in descending order according to the overal Quantity.
Q40) Fulfill missing parts in SQL statement below to create new field that will classify products listed in the
Products table as “Cheap“ when their Price will be lower than 10 EUR or as “Expensive“ otherwise.
06
Test of Basic Knowledge of SQL – Key
Q1) What SQL statement would you use to create SQL database named Test?
Q2) What SQL statement would you use to remove SQL database named Test?
Q3) Assign individual relationships that one can find in ERD (Entity Relationship Diagram) to their appropriate
descriptions.
Q4) Which kind of relationship best describes relationship between Products (A) and OrderDetails (B) tables?
a)
b)
c)
d)
07
Topic: Constraints – PRIMARY KEY, Study Link: https://www.w3schools.com/sql/sql_constraints.asp
Q6) Primary Key is a combination of two types of constraints. Find the correct one in the list below.
Q7) Which field in the Orders table has a role of FOREIGN KEY in relation to Customers table?
a) CustomerID
b) OrderID
c) OrderDate
d) CustomerName
Q8) What SQL statement would you use to put a new record into the Orders table?
a) INSERT INTO Orders (OrderID, CustomerID, OrderDate) VALUES (200, 125, '2018-02-
05');
b) PUT INTO Orders (OrderID, CustomerID, OrderDate) VALUES (200, 125, '2018-02-05');
c) INSERT VALUES (200, 125, '2018-02-05') INTO Orders (OrderID, CustomerID, OrderDate);
d) PUT VALUES (200, 125, '2018-02-05') INTO Orders (OrderID, CustomerID, OrderDate);
Q9) What SQL statement would you use to modify the existing record of CustomerID to 10 for OrderID #10308 in
the Orders table?
Q10) What SQL statement would you use to delete order with OrderID #10308 from the Orders table?
Q11) What SQL statement would you use to add an Age field to the Customers table?
08
Topic: DROP TABLE, Study Link: https://www.w3schools.com/sql/sql_drop_table.asp
Q12) What SQL statement would you use to remove Customers table from Test database?
Q13) Fulfill missing parts in SQL statement below to extract all records from Customers table.
SELECT *
FROM Customers;
Q14) Fulfill missing parts in SQL statement below to extract CustomerName and Address from Customers table.
Q15) Fulfill missing parts in SQL statement below to extract all distinct countries from Customers table.
Q16) Fulfill missing parts in SQL statement below to extract all records from Products table that will include only
products with price higher than 20 EUR.
SELECT *
FROM Products
WHERE Price > 20;
Q17) Fulfill missing parts in SQL statement below to extract all records from Customers table that will include only
those customers who have NULL values in Address field.
SELECT *
FROM Customers
WHERE Address IS NULL;
Q18) Fulfill missing parts in SQL statement below to extract all records from Customers table that will include only
those customers who are from Germany or UK.
SELECT *
FROM Customers
WHERE Country = “Germany” OR Country = “UK” ;
Q19) Fulfill missing parts in SQL statement below to extract all records from Customers table that will include only
those customers who are not from USA.
SELECT *
FROM Customers
WHERE NOT Country = “USA”;
09
Q20) Fulfill missing parts in SQL statement below to extract all records from Products table that will include only
those products that are supplied by supplier with SupplierID #1 and that belong to CategoryID #2.
SELECT *
FROM Products
WHERE SupplierID = 1 AND CategoryID = 2;
Q21) Fulfill missing parts in SQL statement below to arrange records in Products table according to Price in
descending order.
SELECT *
FROM Products
ORDER BY Price DESC;
Q22) Fulfill missing parts in SQL statement below to extract the first 50 records from Customers table.
SELECT TOP 50 *
FROM Customers;
Q23) Fulfill missing parts in SQL statement below to find maximum Price for products listed in Products table.
SELECT MAX(Price)
FROM Products;
Q24) What statement will you use to count number of records within Customers table?
Q25) Fulfill missing parts in SQL statement below to find average Price for products listed in Products table.
SELECT AVG(Price)
FROM Products;
Q26) Fulfill missing parts in SQL statement below to find overal number of ordered products using Quantity field in
OrderDetails table.
SELECT SUM(Quantity)
FROM OrderDetails;
Q27) Fulfill missing parts in SQL statement below to find all customers listed in the Customers table whose name
starts with letter „b“.
SELECT *
FROM Customers
WHERE CustomerName LIKE “b%”;
10
Q28) Fulfill missing parts in SQL statement below to find all customers listed in the Customers table whose name
starts with letter „b“ and ends with letter „o“.
SELECT *
FROM Customers
WHERE CustomerName LIKE “b%o”;
Q29) Fulfill missing parts in SQL statement below to find all customers listed in the Customers table whose name
has letter „b“ in the second position.
SELECT *
FROM Customers
WHERE CustomerName LIKE “_b%”;
Q30) Fulfill missing parts in SQL statement below to find all customers listed in the Customers table who live in
Germany, UK, and USA.
SELECT *
FROM Customers
WHERE Country IN (“Germany“, “UK“, “USA“);
Q31) Fulfill missing parts in SQL statement below to find all products listed in the Products table whose price
belongs to range from 5 to 25 EUR, including the begin and end values.
SELECT *
FROM Products
WHERE Price BETWEEN 5 AND 20;
Q32) What statement would you use to change temporarily name of the CustomerName field to Customer within
Customer table?
Q33) Fulfill missing parts in SQL statement below to select all orders with existing customer information.
Q35) Fulfill missing parts in SQL statement below to select all customers and any orders they might have.
Q36) Fulfill missing parts in SQL statement below to select all customers and all orders.
Q37) What operator would you use to merge selects from two different tables with the same number of columns in
the same order and with similar data types?
a) JOIN
b) MERGE
c) UNITE
d) UNION
Q38) Fulfill missing parts in SQL statement below to calculate overal Quantity for each ProductID and arrange the
resulting list in descending order according to this new metric.
Q39) Fulfill missing parts in SQL statement below to filter products whose overal Quantity is higher than 100 and
arrange the resulting list in descending order according to the overal Quantity.
Q40) Fulfill missing parts in SQL statement below to create new field Price_Level that will classify products listed in
the Products table as “Cheap“ when their Price will be lower than 10 EUR or as “Expensive“ otherwise.
12
---------------------------------------------------------------------------------------------------------------------------------
Deloitte is a leading global provider of audit and assurance, consulting, financial advisory, risk advisory, tax and related services.
Our network of member firms in more than 150 countries and territories serves four out of five Fortune Global 500® companies.
Learn how Deloitte’s approximately 264,000 people make an impact that matters at www.deloitte.com.
Deloitte Central Europe is a regional organization of entities organized under the umbrella of Deloitte Central Europe Holdings
Limited, the member firm in Central Europe of Deloitte Touche Tohmatsu Limited. Services are provided by the subsidiaries and
affiliates of Deloitte Central Europe Holdings Limited, which are separate and independent legal entities. The subsidiaries and
affiliates of Deloitte Central Europe Holdings Limited are among the region’s leading professional services firms, providing
services through more than 6,000 people in 44 offices in 18 countries.
This communication contains general information only, and none of Deloitte Touche Tohmatsu Limited, its member firms, or their
related entities (collectively, the “Deloitte Network”) is, by means of this communication, rendering professional advice or
services. Before making any decision or taking any action that may affect your finances or your business, you should consult a
qualified professional advisor. No entity in the Deloitte Network shall be responsible for any loss whatsoever sustained by any
person who relies on this communication.
“Deloitte” or “DTTL” refers to one or more of Deloitte Touche Tohmatsu Limited, a UK private company limited by guarantee, its
network of member firms, and their related entities. Neither Deloitte Touche Tohmatsu Limited nor any of its member firms has
any liability for each other’s acts or omissions. Each of the member firms is a separate and independent legal entity operating
under the names “Deloitte”, “Deloitte & Touche”, “Deloitte Touche Tohmatsu”, or other related names. “Deloitte Central Europe”,
“DCE”, “the firm” or “we/us” refers to one or more entities organised under the umbrella of Deloitte Central Europe Holdings
Limited, the member firm in Central Europe of Deloitte Touche Tohmatsu Limited. Services are provided by the subsidiaries and
affiliates of Deloitte Central Europe Holdings Limited, which are separate and independent legal entities. Deloitte Advisory s.r.o.
is a subsidiary of Deloitte Central Europe Holdings Limited.
© 2019. For information, contact Deloitte Czech Republic.