Skip to content

Instantly share code, notes, and snippets.

@achad4
Created July 12, 2021 17:35
Show Gist options
  • Save achad4/5470aa32666d9f63ed7fe3edcbdd41e2 to your computer and use it in GitHub Desktop.
Save achad4/5470aa32666d9f63ed7fe3edcbdd41e2 to your computer and use it in GitHub Desktop.
SELECT
lease_dim_id,
reporting_month AS simulated_default_month
FROM
(
--
SELECT
*,
ROW_NUMBER() OVER(PARTITION BY certificate_dim_id ORDER BY (RANDOM() * COALESCE(perc_losses_expected+in_month,0)) DESC) AS rnk
FROM ll_fact_lease_ts ts
LEFT JOIN ll_dim_unit_econ_curves ue ON
(
ue.months_into_term = DATEDIFF('months', move_in_date, reporting_month)
)
)
where rnk = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment