Created
July 12, 2021 17:35
-
-
Save achad4/5470aa32666d9f63ed7fe3edcbdd41e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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