Snowflake Vs MS-SQL - Part 46 - RATIO_TO_REPORT
RATIO_TO_REPORT
If you have a table in which amounts are present and you want to calculate the percentage distribution of those amounts as below:
+----------+--------+----------------+
| STORE_ID | PROFIT | PERCENT_PROFIT |
|----------+--------+----------------|
| 1 | 500.00 | 42 |
| 2 | 250.00 | 21 |
| 3 | 450.00 | 38 |
| 4 | NULL | NULL |
+----------+--------+----------------+
MS-SQL Server
Using the SUM function and OVER clause, you can achieve the above output as below:
In Snowflake, we can use a similar approach as above. However, Snowflake has a different function RATIO_TO_REPORT:
Yogesh Shinde
Comments
Post a Comment