Font size
WorksheetsSWC-KRG 2026 PO-QUIZ 2
Total questions: 20
Worksheet time: 2hrs 37mins
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;
All customers and their total orders, including those with no orders or payments.
Only customers with orders and payments, with the count of orders.
All customers and the count of payments, excluding customers with no orders.
Only customers with both orders and payments, with the count of payments.
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
);
All customers who have placed at least one order.
Customers who have placed orders with an amount greater than 500.
Customers with no orders.
All customers, regardless of their orders.
What does the following query return?
SELECT Region, Amount, SUM(Amount) OVER (PARTITION BY Region) AS TotalRegionSales
FROM Sales;
North: 200, 500; North: 300, 500; South: 400, 900; South: 500, 900
North: 200, 200; North: 300, 300; South: 400, 400; South: 500, 500
North: 200, 500; South: 400, 900
North: 200, 700; South: 400, 700
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;
All customers
Customers with orders
Customers without orders
All orders
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);
Subquery needs GROUP BY DeptID
Subquery is not correlated with DeptID
AVG is invalid in subqueries
Query needs a JOIN
What does this query return?
SELECT Name
FROM Products
WHERE Price > (SELECT AVG(Price) FROM Products);
Laptop
Mouse, Pen
Laptop, Mouse
No rows
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)
);
101
102
101,102
No Rows
SELECT Name, Salary, NTILE(2) OVER (PARTITION BY DeptID ORDER BY Salary DESC)
FROM Employees
WHERE DeptID = 1;
What does this query return?
Alice, 5000, 1; Bob, 6000, 1; Carol, 4000, 2
Bob, 6000, 1; Alice, 5000, 1; Carol, 4000, 2
Bob, 6000, 1; Alice, 5000, 2; Carol, 4000, 2
Alice, 5000, 2; Bob, 6000, 1; Carol, 4000, 1
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)
);
Subquery uses AVG(SUM()), which is invalid
Subquery is not correlated with category
EXISTS is incorrect; use IN
Missing GROUP BY in outer query
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;
Laptop, 1000, Laptop; Mouse, 20, Pen; Pen, 5, Pen
Laptop, 1000, Laptop; Mouse, 20, Mouse; Pen, 5, Pen
Laptop, 1000, Mouse; Mouse, 20, Pen; Pen, 5, Mouse
Laptop, 1000, Laptop; Mouse, 20, Pen; Pen, 5, Mouse
SELECT *
FROM employees e
WHERE EXISTS (
SELECT 1 FROM departments d
WHERE d.manager_id = e.employee_id
);
Employees who manage at least one department
All employees who belong to a department
All managers without departments
Employees who are not managers
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);
3
2
0
5
What will the following query return if the Employees table is empty?
SELECT * FROM Employees WHERE 1 = 0 OR NULL;
All rows
No rows
Error
One row with NULL values
Which query correctly returns the second highest salary from table Salaries(salary) even if duplicates exist?
SELECT MAX(salary) FROM Salaries WHERE salary < (SELECT MAX(salary) FROM Salaries);
SELECT TOP 1 salary FROM (SELECT DISTINCT salary FROM Salaries ORDER BY salary DESC) AS temp;
SELECT salary FROM Salaries ORDER BY salary DESC LIMIT 2;
SELECT salary FROM Salaries LIMIT 1 OFFSET 1;
What's the result of this query on table People(name) with values ('Alice'), ('Bob'), ('NULL')?
SELECT COUNT(*) FROM People WHERE name != 'Bob';
2
1
3
0
SELECT SUM(score) / COUNT(*) FROM Scores;
What is the output?
15
NULL
10
30
SELECT COUNT(*) FROM Numbers WHERE n BETWEEN 4 AND 2;
What is the output?
2
1
0
ERROR
SELECT COUNT(*) FROM Sales HAVING COUNT(*) > 1;
What is the output?
2
1
ERROR
0
