NEW
Font size
WorksheetsData Analysis in SQL: Introduction
Total questions: 20
Worksheet time: 20mins
In a sales table, to compute total revenue per region, which query fragment is essential?
HAVING amount with AVG(region)
WHERE region with COUNT(amount)
ORDER BY amount with MAX(region)
GROUP BY region with SUM(amount)
Which function is best for calculating the average order value per customer?
SUM with ORDER BY customer
AVG with GROUP BY customer
COUNT with WHERE customer
MAX with HAVING customer
What does MIN(amount) compute within each GROUP BY category?
The median value per group
The total count per group
The first value per group
The lowest value per group
Logical SQL order of execution begins with which step?
FROM and JOIN build the row set
SELECT evaluates aliases first
GROUP BY forms categories first
ORDER BY sorts rows before filters
Which column list must match the GROUP BY semantics to avoid errors?
All non-aggregated columns in SELECT
All aggregated columns in WHERE
All alias names in HAVING
All sorted columns in ORDER BY
Which function identifies the largest sale per store when grouped by store_id?
AVG(sale_amount) across store
MAX(sale_amount) per store
COUNT(sale_amount) per store
SUM(sale_amount) across store
A report needs customers with more than 5 orders and average order value above $50. Which filter sequence is correct?
SELECT COUNT(*) > 5 then AVG(total) > 50
WHERE COUNT(*) > 5 and AVG(total) > 50
HAVING COUNT(*) > 5 and AVG(total) > 50
ORDER BY COUNT(*) > 5 then AVG(total) > 50
When grouping by product_category, which SELECT list is valid?
category, SUM(quantity), price
COUNT(*), total_value, region
category, AVG(price), MAX(price)
SUM(quantity), MIN(quantity), supplier
Which option correctly describes the purpose of GROUP BY?
Partitions rows into sets for aggregation
Sorts results alphabetically by category
Applies filters to remove duplicate rows
Combines columns for faster indexing
Which clause is executed after GROUP BY and before SELECT is finalized?
HAVING filters aggregated groups
WHERE filters individual rows
ORDER BY sorts grouped results
FROM constructs initial dataset
You need the average salary from the employees table. Which query correctly uses an aggregate function to produce one scalar value?
SELECT SUM(salary) FROM employees;
SELECT MAX(salary) FROM employees;
SELECT AVG(salary) FROM employees;
SELECT COUNT(salary) FROM employees;
A report needs the highest order total, the lowest order total, and how many orders exist. Which combination of aggregate functions fulfills this?
MAX(), MIN(), COUNT() together
SUM(), AVG(), COUNT() together
AVG(), MIN(), SUM() together
MAX(), SUM(), AVG() together
Which statement reflects the golden rule when using GROUP BY?
All columns must appear in ORDER BY clause
Only numeric columns may be aggregated
Aggregates must be placed after GROUP BY
Every SELECT column is grouped or aggregated
Which statement correctly describes when to use the HAVING clause in SQL?
To filter joins before tables are combined
To filter groups after aggregate functions are computed
To filter columns selected in the projection
To filter rows before grouping operations occur
Why is the condition WHERE SUM(amount) > 1000 incorrect in a grouped query?
SUM must appear only in the ORDER BY clause
WHERE cannot reference aggregate results directly
WHERE requires all columns to be grouped
SUM cannot be used with numeric columns
In the query SELECT category, COUNT(id), SUM(amount) FROM sales GROUP BY category HAVING COUNT(id) > 5 ORDER BY SUM(amount) DESC, what is the role of ORDER BY SUM(amount) DESC?
Sorts rows before grouping by category
Sorts groups by total amount descending
Computes sums for each category first
Filters groups with larger total amounts
Which option best contrasts WHERE and HAVING in grouped queries?
WHERE filters groups; HAVING filters rows
WHERE filters rows; HAVING filters groups
Both WHERE and HAVING filter groups
Both WHERE and HAVING filter rows
Which clause is executed first in SQL’s logical processing order?
ORDER BY sorts final results
WHERE clause filters raw rows
FROM clause identifies tables
SELECT clause processes columns
After rows are grouped, which clause filters those groups before column selection?
ORDER BY filters groups post-grouping
WHERE filters groups post-grouping
HAVING filters groups post-grouping
SELECT filters groups post-grouping
A query is written as SELECT ... FROM ... WHERE ... GROUP BY ... HAVING ... ORDER BY .... Which statement best describes the relationship between written syntax order and logical processing?
Logical order starts at SELECT
Syntax order starts at FROM
They are identical step by step
Logical order starts at FROM
