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

  • 相关阅读:
    函数声明与函数指针
    【LeetCode】三角形最小路径和
    【LeetCode】字符串中的第一个唯一字符
    【LeetCode】基本计算器II
    【LeetCode】二叉树的最小深度
    【LeetCode】加油站
    java中json与对象的转换
    idea2017 无法使用maven3.6.3版本导入依赖
    springboot项目注册为windows系统服务并设置开机自启
    springmvc上传文件
  • 原文地址:https://www.cnblogs.com/yaodidi/p/8323825.html
Copyright © 2011-2022 走看看