0
0
Google Sheetsspreadsheet~20 mins

GROUP BY with aggregation in Google Sheets - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GROUP BY Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Sum of Sales by Region

Given a sales table with columns Region and Sales, what is the result of this query?

=QUERY(A1:B7, "SELECT A, SUM(B) GROUP BY A", 1)

Data in A1:B7:

Region | Sales
North  | 100
South  | 150
North  | 200
East   | 50
South  | 100
East   | 150
Google Sheets
=QUERY(A1:B7, "SELECT A, SUM(B) GROUP BY A", 1)
A
North | 300
South | 150
East  | 200
B
North | 100
South | 150
East  | 50
C
North | 300
South | 250
East  | 200
D
North | 200
South | 100
East  | 150
Attempts:
2 left
💡 Hint

Remember that SUM(B) adds all sales per region.

🔧 Formula Fix
intermediate
2:00remaining
Correct GROUP BY Syntax in QUERY

Which of the following QUERY formulas correctly groups data by Category and counts the number of entries?

A=QUERY(A1:B10, "SELECT A, COUNT(B) GROUP BY A", 1)
B=QUERY(A1:B10, "SELECT A, COUNT(B) WHERE A GROUP BY", 1)
C=QUERY(A1:B10, "SELECT A, COUNT(B) GROUP BY", 1)
D=QUERY(A1:B10, "SELECT COUNT(B) GROUP BY A", 1)
Attempts:
2 left
💡 Hint

Check the order of clauses: SELECT, GROUP BY.

optimization
advanced
2:00remaining
Optimizing Aggregation with Multiple Columns

You want to find the total sales per Region and Product. Which QUERY formula is the most efficient and correct?

A=QUERY(A1:C20, "SELECT A, SUM(C) GROUP BY B", 1)
B=QUERY(A1:C20, "SELECT A, B, SUM(C) GROUP BY A, B", 1)
C=QUERY(A1:C20, "SELECT A, B, SUM(C) GROUP BY A", 1)
D=QUERY(A1:C20, "SELECT SUM(C) GROUP BY A, B", 1)
Attempts:
2 left
💡 Hint

When grouping by multiple columns, list all in GROUP BY clause.

🔧 Formula Fix
advanced
2:00remaining
Identify the Error in GROUP BY Query

What error will this QUERY formula produce?

=QUERY(A1:B10, "SELECT A, SUM(B)", 1)

Assuming columns A and B have data.

Google Sheets
=QUERY(A1:B10, "SELECT A, SUM(B)", 1)
AError: SELECT list expression not in GROUP BY clause and contains nonaggregated column 'A'
BNo error, returns sum of B for all rows
CError: Missing WHERE clause
DError: Invalid column name
Attempts:
2 left
💡 Hint

When using aggregation, non-aggregated columns must be in GROUP BY.

🧠 Conceptual
expert
3:00remaining
Understanding GROUP BY with HAVING Clause

Consider this QUERY formula:

=QUERY(A1:C15, "SELECT A, SUM(C) GROUP BY A HAVING SUM(C) > 100", 1)

What does the HAVING clause do here?

Google Sheets
=QUERY(A1:C15, "SELECT A, SUM(C) GROUP BY A HAVING SUM(C) > 100", 1)
AFilters groups where count of A is greater than 100
BFilters rows where C is greater than 100 before grouping
CFilters rows where A is greater than 100
DFilters groups to only include those where total of C is greater than 100
Attempts:
2 left
💡 Hint

HAVING filters after grouping and aggregation.