Skip to main content
TutorialApplies to: Unified engine deployments
Calculate totals and compare groups without creating a table.

Before you start

You need Workbench and a running SQL engine. Every example includes its own input rows. No catalog, files, credentials, or external data is needed. These queries create no stored tables. Copy the SQL into Workbench and run the statements in order. Compare the result with the table below the query. WITH names input data for one statement only. Each example can run on its own.

1. Calculate totals

How many orders and how much sales?
Expected result Aggregates combine input rows into a summary. Change one thing: Add WHERE region = ‘North’. Expect 4 orders and sales of 85.

2. Compare categories

What are sales by category?
Expected result GROUP BY defines the groups to summarize. Change one thing: Use region instead of category in SELECT, GROUP BY, and ORDER BY. Expect North 85 and South 55.

3. Use two dimensions

What are sales by category and region?
Expected result Each distinct pair forms a group. Change one thing: Add COUNT(*) AS orders. Books/North has 2; all other groups have 1.

4. Filter groups

Which categories exceed 40 in sales?
Expected result HAVING filters after grouping. Change one thing: Change 40 to 50. Only Books remains.

5. Count conditionally

How many large orders are in each region?
Expected result CASE can choose the values passed to an aggregate. Change one thing: Use amount >= 25. South has 2 and North has 1.

6. Count distinct categories

How many categories does each region contain?
Expected result A distinct count removes repeated values within each group. Change one thing: Use COUNT(*) instead. North has 4 orders and South has 2.

Continue

Continue to Combine datasets, or return to Learn Laminar.
Last modified on November 4, 2026