SQL Assessment Questions With Hints Repaired

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Participant Name: ___________________________

Assessment: SQL

This assessment evaluates your knowledge and skills learnt in the following modules:
● Introduction to SQL
● Intermediate SQL
● SQL Server or PostgreSQL (whichever applicable)

Assessment Directions:
● You have 2 hours to complete this test.
● There are 2 sections with 100 total points. The performance point scale is as follows:

80 - 100 60 - 79 0 - 59

Proficient Developing Need improvement

Section A - MCQ / 20

Section B - Case / 80

Total Points / 100

Section A (20 points total)


For Questions 1 to 10 in this section, select the correct answer. (2 points each)

1. What is the full form of SQL? ( )


(a) Structured Query List
(b) Structure Query Language
(c) Sample Query Language
(d) None of the above

2. Which statement is used to delete all rows in a table without having the ( )
action logged?
(a) DELETE
(b) REMOVE
(c) DROP
(d) TRUNCATE

3. SQL Views are also known as __________________. ( )


(a) Simple tables
(b) Virtual tables
(c) Complex tables
(d) Actual Tables

© 2021 Generation: You Employed, Inc.


This study source was downloaded by 100000849835558 from CourseHero.com on 03-12-2023 08:09:12 GMT -05:00 1

https://www.coursehero.com/file/107820248/SQL-Assessment-Questions-with-hints-Repaireddocx/
Participant Name: ___________________________

4. How many Primary keys can there be in a table? ( )


(a) Only 1
(b) Only 2
(c) Depends on number of columns
(d) Depends on DBA

5. Which operator is used to compare a value to a specified list of ( )


values?
(a) ANY
(b) BETWEEN
(c) ALL
(d) IN

6. Which of the following statements is true? ( )


(a) TRUNCATE free the table space while DELETE does not.
(b) Both TRUNCATE and DELETE statements free the table's
space.
(c) Both TRUNCATE and DELETE statements do not free the
table's space.
(d) DELETE free the table space while TRUNCATE does not.

7. Which of the following is true about the HAVING clause? ( )


(a) Similar to the WHERE clause but is used for columns rather
than groups.
(b) Similar to WHERE clause but is used for rows rather than
columns.
(c) Similar to WHERE clause but is used for groups rather than
rows.
(d) Acts exactly like a WHERE clause.

8. How can you change "Thomas" into "Michel" in the "LastName" ( )


column in the Users table?
(a) UPDATE User SET LastName = 'Thomas' INTO LastName =
'Michel'
(b) MODIFY Users SET LastName = 'Michel' WHERE LastName =
'Thomas'
(c) MODIFY Users SET LastName = 'Thomas' INTO LastName =
'Michel'
(d) UPDATE Users SET LastName = 'Michel' WHERE LastName =
'Thomas'

9. Find the cities name with the condition and temperature from table ( )
'whether' where condition = sunny or cloudy but temperature >= 60.

© 2021 Generation: You Employed, Inc.


This study source was downloaded by 100000849835558 from CourseHero.com on 03-12-2023 08:09:12 GMT -05:00 2

https://www.coursehero.com/file/107820248/SQL-Assessment-Questions-with-hints-Repaireddocx/
Participant Name: ___________________________

(a) SELECT city, temperature, condition FROM weather WHERE


condition = 'cloudy' AND condition = 'sunny' OR temperature >=
60
(b) SELECT city, temperature, condition FROM weather WHERE
condition = 'cloudy' OR condition = 'sunny' OR temperature >=
60
(c) SELECT city, temperature, condition FROM weather WHERE
condition = 'sunny' OR condition = 'cloudy' AND temperature >=
60
(d) SELECT city, temperature, condition FROM weather WHERE
condition = 'sunny' AND condition = 'cloudy' AND temperature
>= 60

10 Evaluate the SQL statement: ( )


SELECT a.emp_name, a.sal, a.dept_id, b.maxsal FROM employees a,
(SELECT dept_id, MAX(sal) maxsal FROM employees GROUP BY
dept_id) b WHERE a.dept_id = b.dept_id AND a.sal < b.maxsal;

Which of the following statements is correct?


(a) The statement gives an error at line 1.
(b) The statement gives an error at line 6.
(c) The statement produces the employee name, salary,
department ID, and maximum salary earned in the employee
department for all departments that pay less salary than the
maximum salary paid in the company.
(d) The statement produces the employee name, salary,
department ID, and maximum salary earned in the employee
department for all employees who earn less than the maximum
salary in their department.

Section B (80 points total)

Context (This task may be carried out in SQL Server or PostgreSQL)

For PostgreSQL, please download the sql to install the database from:
https://github.com/pthom/northwind_psql

For SQL Server, please download the sql to install the database from:
https://github.com/microsoft/sql-server-samples/tree/master/samples/databases/northwind-
pubs

Your manager is asking you to generate some results in the database-Northwind.


The structure of the database is shown below:

© 2021 Generation: You Employed, Inc.


This study source was downloaded by 100000849835558 from CourseHero.com on 03-12-2023 08:09:12 GMT -05:00 3

https://www.coursehero.com/file/107820248/SQL-Assessment-Questions-with-hints-Repaireddocx/
Participant Name: ___________________________

© 2021 Generation: You Employed, Inc.


This study source was downloaded by 100000849835558 from CourseHero.com on 03-12-2023 08:09:12 GMT -05:00 4

https://www.coursehero.com/file/107820248/SQL-Assessment-Questions-with-hints-Repaireddocx/
Participant Name: ___________________________

Tasks

1. Write a query to get current Product list (Product ID and name). (1 point) Hint:
discontinued = 0

SELECT product_id, product_name FROM Products where discontinued=0

2. Write a query to get Product list (name, unit price) where products cost between $15 and
$25. (1 point) Hint: discontinued = 0

3. Write a query to get Product list (name, units on order, units in stock) of stock is less than
the quantity on order. (3 points) Hint: discontinued = 0

4. Select all product names, unit price and the supplier region that don’t have suppliers
from the USA region. (3 points) Hint: Inner Join

5. Get all customer names that live in the same city as the employees. (3 points) Hint:
subquery

6. Get the number of customers living in each country Where the number of residents is
greater than 10 and sort the countries in descending order. (3 points) Hint: Group by …
Having…

7. Get the number of employees who have been working more than 5 year in the company.
(3 points) Hint: date_part(), age()

8. When was the first employee hired in the company? (3 points) Hint: Limit

9. Display the Customer Name (ContactName) and the number of orders ordered by this
customer, for customers living in the UK. Arrange the result based on the number of
orders from the greatest to the lowest. (5 points) Hint: COUNT(orders.order_id)

10. Get the number of orders for each displayed Customer Name (ContactName) living in
the USA and restrict the result for those customers who ordered more than five orders.
Label any un-named column(s) with a meaningful name(s) (5 points) Hint: WHERE,
AND, GROUP BY, HAVING

11. Get the total quantity ordered for each displayed product name with unit price higher
than 30. Restrict the result for those products having total ordered quantity in the range
between 1000 and 1500. Label any un-named column(s) with a meaningful name(s).
(5 points) Hint: WHERE, AND, GROUP BY, HAVING

12. For each of the following countries (USA, Italy and France), display the country name in
addition to the number of suppliers living in this country and having a fax number. Sort
the result by the country name in a descending order and give a meaningful name(s) for
any un-named column(s). (5 points) Hint: AND fax is NOT NULL

13. Display the first name, job title and the city of all employees not working as Sales
Managers and living in the same city as the employee with first name: Michael. Sort

© 2021 Generation: You Employed, Inc.


This study source was downloaded by 100000849835558 from CourseHero.com on 03-12-2023 08:09:12 GMT -05:00 5

https://www.coursehero.com/file/107820248/SQL-Assessment-Questions-with-hints-Repaireddocx/
Participant Name: ___________________________

the result by the first name of the employees in an ascending order. (8 points) Hint:
Subquery city from employees

SELECT first_name, title, city

FROM employees

WHERE city IN (SELECT city

FROM employees

WHERE first_name = 'Michael')

AND title != 'Sales Manager';

14. Display the first name, job title and the country of all employees working as Sales
Representatives and living in the same country as the manager (Note: the manager
is the person that doesn’t report to anyone). Sort the result by the first name of the
employees in a descending order. (8 points) Hint: WHERE reports_to IS NULL

SELECT first_name, title, city

FROM employees

WHERE country IN (SELECT country

FROM employees

WHERE first_name = 'Michael')

AND title = 'Sales Manager';

15. Display the first name, address and the hire date of all employees having an address
containing 2 and who were hired before the employee with first name: Steven. Sort the
result by the first name of the employees in an ascending order. (8 points) Hint: LIKE

SELECT first_name, address,hire_date

FROM employees

WHERE address LIKE '%2%'

AND hire_date < (

SELECT hire_date

FROM employees

WHERE first_name='Steven'

© 2021 Generation: You Employed, Inc.


This study source was downloaded by 100000849835558 from CourseHero.com on 03-12-2023 08:09:12 GMT -05:00 6

https://www.coursehero.com/file/107820248/SQL-Assessment-Questions-with-hints-Repaireddocx/
Participant Name: ___________________________

ORDER BY first_name;

16. Display the first name, country and the birth date of all employees who were born before
1958 and are working in the same country as the employee with first name: Laura. Sort
the result by the first name of the employees in an ascending order. (8 points)

SELECT first_name, country, birth_date

FROM employees

WHERE EXTRACT( YEAR from birth_date) < 1958 and country IN (SELECT country

FROM employees

WHERE first_name = 'Laura')

ORDER BY first_name;

17. For each displayed country name, show how many products were supplied by suppliers
who have got a fax number. Restrict the result for those countries having less than five
supplied products. Label any un-named column(s) by a meaningful name(s). (8 points)

© 2021 Generation: You Employed, Inc.


This study source was downloaded by 100000849835558 from CourseHero.com on 03-12-2023 08:09:12 GMT -05:00 7

https://www.coursehero.com/file/107820248/SQL-Assessment-Questions-with-hints-Repaireddocx/
Powered by TCPDF (www.tcpdf.org)

You might also like