How to use the percent key word in the snowflake query

不打扰是莪最后的温柔 提交于 2019-12-13 22:38:39

问题


SELECT  NBR, Customers, status
FROM (
  SELECT  NBR, Customers, Code AS status
  FROM   CCC AS CS 
  INNER JOIN AAA AS AC ON CCC.B2= ACT.B1 AND CSS.B2 = ACT.B1
) AS rst
WHERE status IN ('A', 'T')
ORDER BY NBR LIMIT 100 PERCENT

回答1:


I saw you other post. Not 100% sure what you are trying to do, but you might want to consider using a windows function like ratio_to_report. See the example below. Here is a link to the windows functions

https://docs.snowflake.net/manuals/sql-reference/functions-analytic.html

select 
        store_id, profit, 
        100 * ratio_to_report(profit) over () as percent_profit
    from store_profit
    order by store_id;
+----------+--------+----------------+
| STORE_ID | PROFIT | PERCENT_PROFIT |
|----------+--------+----------------|
|        1 | 300.00 |    30.00000000 |
|        2 | 250.00 |    25.00000000 |
|        3 | 450.00 |    45.00000000 |
|        4 |   NULL |           NULL |
+----------+--------+----------------+



来源:https://stackoverflow.com/questions/59218213/how-to-use-the-percent-key-word-in-the-snowflake-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!