【问题标题】:How to use the percent key word in the snowflake query如何在雪花查询中使用百分比关键字
【发布时间】:2020-03-31 17:54:54
【问题描述】:
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

【问题讨论】:

  • 如果您为此类问题提供示例数据集和所需输出,这将有助于我们更好地了解您的目标。

标签: sql snowflake-cloud-data-platform snowflake-schema


【解决方案1】:

我看到你的其他帖子。不是 100% 确定您要做什么,但您可能需要考虑使用诸如 ratio_to_report 之类的 windows 函数。请参见下面的示例。这是windows函数的链接

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 |
+----------+--------+----------------+

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    • 2021-10-02
    • 1970-01-01
    • 2021-11-12
    • 1970-01-01
    相关资源
    最近更新 更多