See your SQL window
What does each row see? Change the window, then walk through the table to find out.
SQL lab · Event ticketing
Explore a synthetic application for buying tickets to events. Customers place orders for event sessions; order items contain ticket quantities and prices. Refunds, campaigns, browsing events and exchange rates complete the picture.
How the models relate
Events belong to partners and have scheduled sessions. Each order can contain several ticket lines and refunds. Campaigns have daily spending and email sends; browsing events can be anonymous or linked to a customer.
flowchart LR
cities["cities · location and timezone"] -->|city| partners
cities -->|city| events
partners -->|partner_id| partner_tier_history
partners -->|partner_id| events
events -->|event_id| event_sessions
customers -->|customer_id| orders["orders · order versions"]
orders -->|order_id, deduplicate first| order_items
orders -->|order_id, deduplicate first| refunds
event_sessions -->|session_id| order_items
campaigns -->|campaign_id, optional| orders
campaigns -->|campaign_id| marketing_spend_daily
campaigns -->|campaign_id| crm_sends
customers -->|customer_id| crm_sends
customers -->|customer_id, optional login| web_events
fx_rates["fx_rates · daily currency rates"] -.->|currency plus as-of order date| orders
Arrows show logical join paths from the dataset generator, not enforced foreign keys. orders contains multiple versions per order_id: deduplicate before joining. Aggregate ticket lines and refunds separately to avoid multiplying amounts. Partner tiers require an effective-date join; exchange rates require currency and an as-of date lookup. The practice data deliberately includes orphan records, duplicate customers and missing weekend rates.
Tables and columns
Loading dataset…
Build a window on ticketing tables
Choose the table and columns, then drag a clause into its slot or click to add it. Each change executes the SQL and updates the animation.
Output columns
Loading table columns…
Samples are separate lab_sample_* views, not the full dataset. Switch to Full table to query every row. Partitions above 60 rows execute with results only; add WHERE to narrow them. Extra sort columns break ties for position-based functions. RANK and RANGE keep peers.
Uncheck to display all rows returned by the SQL, without the previous 200-row cap. A LIMIT written in the SQL still applies. Output limits do not shorten partitions or frames; sample views and WHERE do change the input.
Query animation
Select any result row or matrix row. Row-label buttons also work with the keyboard. Selecting a comparison matrix explains that reference frame; the actual SQL result stays unchanged. Manual selection pauses playback.
Selected row calculation
Input columns below follow SELECT, including aliases and selected expressions. The window result is shown in the output table. “Source row” is a visual identifier linking tables and matrices, not an additional SQL column. Dependency badges mean a selected expression uses a window column; the expression itself may differ from the window argument.
Ver fila completa
All original columns of the selected source row. Unmarked columns are context, not value, partition or order inputs to this window.
Square, staircase and selected window
Rows and columns use the same source-row numbers as the tables. The full input partition remains visible even when only 10 output rows are displayed. Cells show frame membership: NULL rows can belong to a frame even though SUM, AVG and COUNT(column) ignore their values. The first two options compare aggregate frames; choose Ventana real for the actual function and frame. Without a window ORDER BY, the first two options show identical membership.
Visual scope: one standalone SUM, AVG, COUNT, ROW_NUMBER, RANK, LAG or LEAD window, with AS alias, on one table (optional WHERE, ORDER BY and LIMIT). Joins, CTEs, multiple windows and other SQL still execute, with results only. Visual partitions are limited to 60 rows. LAG/LEAD offsets must be non-negative integer literals. Ranking highlights show ranking context, not an aggregate frame.
1. Build a window
Drag a syntax block into its matching slot, or click it to add it. Remove a clause with ×.
SUM(amount) OVER ( ) Drop blocks into their matching slots.
SELECT id, customer, order_n, amount,
SUM(amount) OVER (
PARTITION BY customer
) AS window_sum
FROM sales
ORDER BY customer, order_n, id; Loading DuckDB-Wasm…
Queries run automatically when blocks change. DuckDB executes locally in your browser; the SUM column shows its actual results.
Blocks and controls stay in sync. ROWS adds id as a tie-breaker. Adding a frame also adds its required ordering.
2. Follow a row
Row 1 of 6| Row | Customer | order_n | Amount | In frame? | SUM · DuckDB |
|---|---|---|---|---|---|
| A | 1 | 100 | |||
| A | 2 | 50 | |||
| A | 2 | 25 | |||
| B | 1 | 200 | |||
| B | 2 | 40 | |||
| B | 3 | 60 |
3. See every frame at once
Both views follow the current row together. Columns are input rows #1–#6; rows are output rows #1–#6. Solid blocks show included inputs, ● marks the current output row. RANGE includes ties, so the staircase has a wider step at order_n = 2.
Each matrix row is an output row. A filled cell means the input row in that column contributes to its SUM.
| Output ↓ / Input → | #1 | #2 | #3 | #4 | #5 | #6 |
|---|
This is a model of SQL semantics, not an animation of a database engine's physical execution. Example data is fixed; order_n deliberately repeats for customer A.