zoukankan      html  css  js  c++  java
  • 分析函数

    1.语法

    function1(argument1,argument......argumentN)  --(function处理的数据源(table)中,包含所有表的字段,不受partition-by的影响,与group by 不同)

    over([partition-by-clause] [order-by-clause] [windowing-clause])

    2.语法解释

    argument --处理的字段

    partition-by --分区子句,限制function处理的上下边界

    order by -- 对分区中的数据进行排序 ,当windowing-clause 为 rows between unbounded preceding and current now(当前列),影响最大

    windowing-clause --是在partition-by的条件下进行限制,例如rows between unbounded preceding and unbounded following,指的是partition-by的条件下全部数据,不能跨分区

    3.例子

    3.1 求product, country, region,year分区下每年的销售额

    select  year, week,sale,
        sum (sale) over(
              partition by product, country, region,year
              order by week  --行排序没有作用
       rows between unbounded preceding and unbounded following  --跨整个分区
               ) running_sum_ytd
      from sales_fact
      where country in ('Australia')  and product ='Xtend Memory'
      order by product, country,year, week

    3.2 求product, country, region,year分区下到当前周的销售额

    select  year, week,sale,
        sum (sale) over(
              partition by product, country, region,year
              order by week  --行排序起到关键性作用
       rows between unbounded preceding and current now  --没有跨整个分区,在分区首列到当前列
               ) running_sum_ytd
      from sales_fact
      where country in ('Australia')  and product ='Xtend Memory'
      order by product, country,year, week

  • 相关阅读:
    「CH6801」棋盘覆盖
    「POJ3613」Cow Relays
    「Luogu4556」Vani有约会-雨天的尾巴
    The Proof of Fibonacci GCD
    Ubuntu flatabulous 主题
    CSP-S 2019 复赛游记
    「Luogu1402」酒店之王
    HDU/5499/模拟
    cfedu/A/求和
    HDU<1372>/bfs
  • 原文地址:https://www.cnblogs.com/yaodidi/p/8323825.html
Copyright © 2011-2022 走看看