dbt Labs dbt-Analytics-Engineering Question Answer
Examine the code:
select
left(customers.id, 12) as customer_id,
customers.name as customer_name,
case when employees.employee_id is not null then true else false end as is_employee,
event_signups.event_name,
event_signups.event_date,
sum(case when visit_accomodations.type = 'hotel' then 1 end)::boolean as booked_hotel,
sum(case when visit_accomodations.type = 'car' then 1 end)::boolean as booked_ride
from customers
-- one customer can sign up for many events
left join event_signups
on left(customers.id, 12) = event_signups.customer_id
-- an event signup for a single customer can have many types of accommodations booked
left join visit_accomodations
on event_signups.signup_id = visit_accomodations.signup_id
and left(customers.id, 12) = visit_accomodations.customer_id
-- an employee can be a customer
left join employees
on left(customers.id, 12) = employees.customer_id
group by 1, 2



