Introduction
Models in dbt are like recipes that tell the computer how to prepare your data. They help you organize and transform raw data into useful information.
Jump into concepts and practice - no test required
Models in dbt are like recipes that tell the computer how to prepare your data. They help you organize and transform raw data into useful information.
select column1, column2, aggregate_function(column3) as new_column from source_table where condition group by column1, column2
select * from raw_customersselect customer_id, count(order_id) as total_orders from raw_orders group by customer_id
select customer_id, sum(amount) as total_spent from raw_payments where payment_date >= '2024-01-01' group by customer_id
This dbt model creates a table showing how many orders each customer has made.
-- models/customer_orders.sql select customer_id, count(order_id) as order_count from raw_orders group by customer_id
Models help you build your data step-by-step, making it easier to understand and maintain.
dbt automatically manages the order of models based on dependencies.
Using models means you write SQL once and reuse it everywhere.
Models are the main way to transform raw data into useful tables or views.
They organize your data work clearly and make it easy to update.
dbt runs models to build your data project in the right order.
models/my_model.sql containing a SELECT statement uses a .sql file with a SELECT statement, which is correct for a dbt model.SELECT user_id, COUNT(*) AS orders_count FROM raw.orders GROUP BY user_id
SELECT customer_id, date, SUM(amount) AS total FROM sales GROUP BY customer_id