wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

SWC-KRG 2026 PO-QUIZ 2

Total questions: 20

Worksheet time: 2hrs 37mins

Name
Class
Date
1.

Given three tables: Customers (CustomerID, CustomerName), Orders (OrderID, CustomerID, OrderDate), and Payments (PaymentID, OrderID, Amount), what does the following query return?

SELECT c.CustomerName, COUNT(o.OrderID) as OrderCount

FROM Customers c

LEFT JOIN Orders o ON c.CustomerID = o.CustomerID

LEFT JOIN Payments p ON o.OrderID = p.OrderID

GROUP BY c.CustomerName;

a)
  1. All customers and their total orders, including those with no orders or payments.

b)
  1. Only customers with orders and payments, with the count of orders.

c)
  1. All customers and the count of payments, excluding customers with no orders.

d)
  1. Only customers with both orders and payments, with the count of payments.

2.

What is the output of the query?

SELECT e1.Name AS Employee, e2.Name AS Manager

FROM Employees e1

LEFT JOIN Employees e2 ON e1.ManagerID = e2.EmployeeID

WHERE e2.Name IS NULL;

4 lines
3.

Given the table Orders (OrderID, CustomerID, OrderAmount) and Customers (CustomerID, CustomerName), what does the following correlated subquery return?

SELECT CustomerName

FROM Customers c

WHERE EXISTS (

SELECT 1

FROM Orders o

WHERE o.CustomerID = c.CustomerID AND o.OrderAmount > 500

);

a)
  1. All customers who have placed at least one order.

b)
  1. Customers who have placed orders with an amount greater than 500.

c)
  1. Customers with no orders.

d)
  1. All customers, regardless of their orders.

4.

What does the following query return?

SELECT Region, Amount, SUM(Amount) OVER (PARTITION BY Region) AS TotalRegionSales

FROM Sales;

a)
  1. North: 200, 500; North: 300, 500; South: 400, 900; South: 500, 900

b)
  1. North: 200, 200; North: 300, 300; South: 400, 400; South: 500, 500

c)
  1. North: 200, 500; South: 400, 900

d)
  1. North: 200, 700; South: 400, 700

5.

Given Customers (CustomerID, Name) and Orders (OrderID, CustomerID), what does this query return?

SELECT c.Name

FROM Customers c

LEFT JOIN Orders o ON c.CustomerID = o.CustomerID

WHERE o.OrderID IS NULL;

a)
  1. All customers

b)
  1. Customers with orders

c)
  1. Customers without orders

d)
  1. All orders

6.

This query should return employees with above-average salary in their department, but it fails. Why?

SELECT Name

FROM Employees e

WHERE Salary > (SELECT AVG(Salary) FROM Employees);

a)
  1. Subquery needs GROUP BY DeptID

b)
  1. Subquery is not correlated with DeptID

c)
  1. AVG is invalid in subqueries

d)
  1. Query needs a JOIN

7.

What does this query return?

SELECT Name

FROM Products

WHERE Price > (SELECT AVG(Price) FROM Products);

a)
  1. Laptop

b)
  1. Mouse, Pen

c)
  1. Laptop, Mouse

d)
  1. No rows

8.

What does this query return?

SELECT CategoryID

FROM Products

WHERE ProductID IN (

SELECT ProductID

FROM Sales

GROUP BY ProductID

HAVING SUM(Amount) > (SELECT AVG(SUM(Amount)) FROM Sales GROUP BY ProductID)

);

a)

101

b)

102

c)

101,102

d)

No Rows

9.

SELECT Name, Salary, NTILE(2) OVER (PARTITION BY DeptID ORDER BY Salary DESC)

FROM Employees

WHERE DeptID = 1;

What does this query return?

a)
  1. Alice, 5000, 1; Bob, 6000, 1; Carol, 4000, 2

b)
  1. Bob, 6000, 1; Alice, 5000, 1; Carol, 4000, 2

c)
  1. Bob, 6000, 1; Alice, 5000, 2; Carol, 4000, 2

d)
  1. Alice, 5000, 2; Bob, 6000, 1; Carol, 4000, 1

10.

This query aims to find products with sales above the average sales of their category, but it fails. Why?

SELECT p.ProductName

FROM Products p

WHERE EXISTS (

SELECT 1

FROM Sales s

WHERE s.ProductID = p.ProductID

HAVING SUM(s.Amount) > (SELECT AVG(SUM(s2.Amount)) FROM Sales s2 GROUP BY s2.ProductID)

);

a)
  1. Subquery uses AVG(SUM()), which is invalid

b)
  1. Subquery is not correlated with category

c)
  1. EXISTS is incorrect; use IN

d)
  1. Missing GROUP BY in outer query

11.

What does this query return?

SELECT Name, Price, LAST_VALUE(Name) OVER (PARTITION BY CategoryID ORDER BY Price DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)

FROM Products;

a)
  1. Laptop, 1000, Laptop; Mouse, 20, Pen; Pen, 5, Pen

b)
  1. Laptop, 1000, Laptop; Mouse, 20, Mouse; Pen, 5, Pen

c)
  1. Laptop, 1000, Mouse; Mouse, 20, Pen; Pen, 5, Mouse

d)
  1. Laptop, 1000, Laptop; Mouse, 20, Pen; Pen, 5, Mouse

12.

SELECT *

FROM employees e

WHERE EXISTS (

SELECT 1 FROM departments d

WHERE d.manager_id = e.employee_id

);

a)

Employees who manage at least one department

b)

All employees who belong to a department

c)

All managers without departments

d)

Employees who are not managers

13.

You have a table Numbers with a single column num containing values: (1), (2), (3), (4), (5). What does this query return?

SELECT COUNT(*)

FROM Numbers

WHERE num NOT IN (SELECT num FROM Numbers WHERE num % 2 = 0);

a)

3

b)

2

c)

0

d)

5

14.

What will the following query return if the Employees table is empty?

SELECT * FROM Employees WHERE 1 = 0 OR NULL;

a)

All rows

b)

No rows

c)

Error

d)

One row with NULL values

15.

Which query correctly returns the second highest salary from table Salaries(salary) even if duplicates exist?

a)

SELECT MAX(salary) FROM Salaries WHERE salary < (SELECT MAX(salary) FROM Salaries);

b)

SELECT TOP 1 salary FROM (SELECT DISTINCT salary FROM Salaries ORDER BY salary DESC) AS temp;

c)

SELECT salary FROM Salaries ORDER BY salary DESC LIMIT 2;

d)

SELECT salary FROM Salaries LIMIT 1 OFFSET 1;

16.

What's the result of this query on table People(name) with values ('Alice'), ('Bob'), ('NULL')?

SELECT COUNT(*) FROM People WHERE name != 'Bob';

a)

2

b)

1

c)

3

d)

0

17.

SELECT SUM(score) / COUNT(*) FROM Scores;

What is the output?

a)

15

b)

NULL

c)

10

d)

30

18.

SELECT COUNT(*) FROM Numbers WHERE n BETWEEN 4 AND 2;

What is the output?

a)

2

b)

1

c)

0

d)

ERROR

19.

SELECT COUNT(*) FROM Sales HAVING COUNT(*) > 1;

What is the output?

a)

2

b)

1

c)

ERROR

d)

0

20.

SELECT A.id, B.value

FROM A

LEFT JOIN B ON A.id = B.id

WHERE B.value IS NOT NULL;

What type of join does this behave like?

a)

LEFT JOIN

b)

INNER JOIN

c)

RIGHT JOIN

d)

FULL OUTER JOIN