Creating a model in dbt helps you turn raw data into clean, organized tables. This makes it easier to analyze and understand your data.
Creating your first model in dbt
select column1, column2, aggregate_function(column3) as new_column from source_table where condition
This is a basic SQL SELECT statement used inside a dbt model file.
Each model is a SQL file that creates a table or view in your data warehouse.
select * from raw.customersselect customer_id, count(order_id) as total_orders from raw.orders where order_status = 'completed' group by customer_id
select customer_id, upper(customer_name) as customer_name_upper from raw.customers
This simple dbt model selects active users from the raw.users table.
Save this SQL in your dbt project's models folder as my_first_model.sql. When you run dbt run, it will create a table or view with this data.
-- File: models/my_first_model.sql
select
id,
name,
created_at
from raw.users
where active = trueModel files must be saved in the models folder of your dbt project.
Run dbt run to build your models and create tables or views in your data warehouse.
Use simple SQL first, then add complexity as you learn.
dbt models are SQL files that transform raw data into clean tables.
Save your SQL code in the models folder and run dbt run to create the model.
Start with simple SELECT statements to build your first model.