Skip to content

Instantly share code, notes, and snippets.

@robert8138
Last active February 24, 2020 13:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robert8138/d243a987bb200d8e3e3477525fcbd700 to your computer and use it in GitHub Desktop.
Save robert8138/d243a987bb200d8e3e3477525fcbd700 to your computer and use it in GitHub Desktop.
Fact and Dimension Tables in Actions
SELECT
b.dim_market
, SUM(a.m_bookings) AS m_bookings
FROM (
SELECT
id_listing
, 1 AS m_bookings
, m_a # not used (for illustration only)
, m_b # not used (for illustration only)
, m_c # not used (for illustration only)
FROM
fct_bookings
WHERE
ds BETWEEN '{{ last_sunday }}' AND '{{ this_saturday }}'
) a
JOIN (
SELECT
id_listing
, dim_market
, dim_x # not used (for illustration only)
, dim_y # not used (for illustration only)
, dim_z # not used (for illustration only)
FROM
dim_listings
WHERE
ds BETWEEN '{{ latest_ds }}'
) b
ON (a.id_listing = b.id_listing)
GROUP BY
b.dim_market
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment