Last active
March 9, 2020 15:51
-
-
Save YiLi225/1465a10c4416fea7e3970de91480b6fb 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
--- 2) Running total/frequency | |
SELECT | |
DAT.NUM_VAR, | |
SUM(NUM_VAR) OVER (PARTITION BY JOIN_ID) AS TOTAL_SUM, | |
ROUND(CUM_SUM / SUM(NUM_VAR) OVER (PARTITION BY JOIN_ID), 4) AS CUM_FREQ | |
FROM | |
( | |
SELECT | |
T.*, | |
SUM(NUM_VAR) OVER (ORDER BY NUM_VAR ROWS UNBOUNDED PRECEDING) AS CUM_SUM, | |
CASE WHEN ID_VAR IS NOT NULL THEN '1' END AS JOIN_ID | |
FROM CURRENT_TABLE T | |
) DAT | |
ORDER BY CUM_FREQ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment