Lab: build a small sales dataset
Apply the object and SQL concepts to a small, disposable sales table and answer a business question.
Understand the idea
Run the first database/schema lesson before this lab. You need CREATE TABLE on the lab schema and an authorized warehouse for the queries. Keep the same session because the table is temporary.
| Concept | What it means |
|---|---|
| Setup | Create a temporary table in the learning schema. |
| Transform | Clean a region label and preserve a missing amount. |
| Query | Group the sales and count missing values. |
| Cleanup | Drop only the named lab table after reviewing the result. |
A concrete example
EAST: 2 orders, 0 missing amounts, sales 100. WEST: 1 order, 1 missing amount, sales NULL. The final statement removes only this disposable lab table.
Remember: No known amount contributes to that group. Reporting zero would imply a known total and hide the missing-data issue.
Explain it step by step · full theory
Understand the idea
Run the first database/schema lesson before this lab. You need CREATE TABLE on the lab schema and an authorized warehouse for the queries. Keep the same session because the table is temporary.
Predict the result before running it. East has two known orders totaling 100. West has one row with an unknown amount. COUNT(*) and COUNT(AMOUNT) let you distinguish no rows from rows whose values are missing.
Words used in this lesson
- Setup
- Create a temporary table in the learning schema.
- Transform
- Clean a region label and preserve a missing amount.
- Query
- Group the sales and count missing values.
- Cleanup
- Drop only the named lab table after reviewing the result.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Lab: build a small sales dataset
Choose the input
Apply the object and SQL concepts to a small, disposable sales table and answer a business question.
Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.
Read the complete diagram explanation
- Choose the input
Apply the object and SQL concepts to a small, disposable sales table and answer a business question.
- Apply the SQL
Run the first database/schema lesson before this lab. You need CREATE TABLE on the lab schema and an authorized warehouse for the queries. Keep the same session because the table is temporary.
- Explain the result
No known amount contributes to that group. Reporting zero would imply a known total and hide the missing-data issue.
Try the SQL or command
Read → predict → run in your learning environment → compare. You can also learn by reading without an account.
New to SQL? Where to run it and how to read it
A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.
- No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
- For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
- Read the entire example, including comments beginning with
--. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor. - Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
- SELECT / FROM
- Choose the values to return / identify their input.
- VALUES / COLUMN1
- VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
- AS / WITH
- AS gives a result a readable name. WITH names a temporary query step within one statement.
- NULL / ::
- NULL means missing or unknown. The :: notation converts a value to a named data type.
- Session
- One connection and its settings. Keep related transaction steps in the same session.
- Database.schema.table
- A full address for stored data. It is separate from the warehouse that processes queries.
Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →
Help with common practice errors
- No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
- Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
- Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
- Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.
Before running this lesson
Use an authorized learning account and warehouse. VALUES examples need no stored tables. Object-changing examples use separate disposable tables in L2_OBJECTS_LAB.SALES from the first lesson; run each setup once with a fresh name.
Run the business query
CREATE TEMPORARY TABLE L2_OBJECTS_LAB.SALES.BUSINESS_LAB
(ID NUMBER, REGION VARCHAR, AMOUNT NUMBER(10,2));
INSERT INTO L2_OBJECTS_LAB.SALES.BUSINESS_LAB VALUES
(1,' east ',40),(2,'EAST',60),(3,'west',NULL);
SELECT UPPER(TRIM(REGION)) AS REGION, COUNT(*) AS ORDERS,
COUNT(*) - COUNT(AMOUNT) AS MISSING_AMOUNTS, SUM(AMOUNT) AS SALES
FROM L2_OBJECTS_LAB.SALES.BUSINESS_LAB
GROUP BY UPPER(TRIM(REGION)) ORDER BY REGION;
-- After reviewing the result:
DROP TABLE L2_OBJECTS_LAB.SALES.BUSINESS_LAB;What to expect and why
EAST: 2 orders, 0 missing amounts, sales 100. WEST: 1 order, 1 missing amount, sales NULL. The final statement removes only this disposable lab table.
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
Why is West sales NULL rather than zero?
Compare your reasoning
No known amount contributes to that group. Reporting zero would imply a known total and hide the missing-data issue.