> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Build a notebook

> Build a SQL notebook with a setup cell, an analysis cell, and a short explanation. Run it for two regions and inspect the recorded results.

TutorialApplies to: Unified engine deployments

Build a SQL notebook with a setup cell, an analysis cell, and a short explanation. Run it for two regions and inspect the recorded results.

## Before you start

You need SQL notebooks and engine execution. No catalog is required. This lesson uses a temporary view, which is a named query available only in its current session.

## 1. Create the document

1. Open **Notebooks → New notebook**.
2. Name it `Lesson - regional analysis` and choose **SQL**.
3. Add a Markdown cell with this text:

```markdown theme={"theme":{"light":"github-light","dark":"github-dark"}}
## Regional sales
Six sample orders total 140. North contributes 85 and South contributes 55.
The first code cell creates a session-local view. The second reads it.
```

## 2. Add the setup cell

Add a code cell with this SQL:

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
CREATE OR REPLACE TEMP VIEW lesson_orders AS
WITH orders(order_id, category, region, amount) AS (
  VALUES
    (1, 'Books',  'North', 20),
    (2, 'Games',  'South', 30),
    (3, 'Games',  'North', 15),
    (4, 'Books',  'North', 40),
    (5, 'Garden', 'South', 25),
    (6, 'Garden', 'North', 10)
)
SELECT * FROM orders;
```

The view contains six rows when queried. It is not a stored Iceberg table. Creating a new session does not copy the view from the old one.

## 3. Add a parameter and analysis cell

Open **Notebook actions → Parameters**. Define `region` as a required, non-null String with default `North`. Save the definition.

Add a second code cell:

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT category, SUM(amount) AS sales
FROM lesson_orders
WHERE region = :region
GROUP BY category
ORDER BY category;
```

This cell needs both the setup cell and the notebook parameter. Copy it into the notebook, rather than running it by itself in a new Workbench session.

## 4. Run in order

1. Save the notebook and check **Saved to server**.
2. Select **Open session** and wait for it to be ready.
3. Select **Run all**.
4. Inspect each cell's state and the second cell's output.

Expect **Books = 60**, **Games = 15**, and **Garden = 10**. The setup cell runs first because it appears first in the document. Markdown is not submitted as SQL.

Open the recorded run in History. Check its document revision and parameter values. A successful save is different from a completed run.

## Change one thing

Set the current `region` parameter value to `South` and run the analysis cell again. Expect **Games = 30** and **Garden = 25**. Compare the new recorded run with the North run.

Now open a fresh session and use **Run all**. Expect the same South totals after the setup cell recreates the view. This shows why the notebook keeps its setup steps in the document.

## Check the result

The notebook contains explanation, setup, and analysis in order. North totals 85. South totals 55. The saved document survives a session change, while its temporary view must be recreated.

## Clean up

Close the lesson sessions after execution has finished. This removes their session-local state. Keep the notebook or delete only `Lesson - regional analysis`. No stored tables were created.

## Continue

[Automate an analysis](https://docs.e6data.com/transformation/learn/automate.md) to publish a repeatable result. The notebook sessions and parameters guides explain these controls in more detail.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.