wap网站 区别,公司宣传册设计制作,微信公众号模板素材网站,新媒体营销方式有几种1、开窗函数是什么#xff1f; 开窗函数用于为行定义一个窗口#xff08;这里的窗口是指运算将要操作的行的集合#xff09;#xff0c;它对一组值进行操作#xff0c;不需要使用 GROUP BY 子句对数据进行分组#xff0c;能够在同一行中同时返回基础行的列和聚合列。 2、…1、开窗函数是什么 开窗函数用于为行定义一个窗口这里的窗口是指运算将要操作的行的集合它对一组值进行操作不需要使用 GROUP BY 子句对数据进行分组能够在同一行中同时返回基础行的列和聚合列。 2、开窗函数有什么用 开窗函数的功能本质是聚合但是相比聚合开窗函数可以提供的信息更多。 3、first_value/last_value 函数 first_value()over(partition by 列名1列名2 order by 列名1列名2)是求一组数据的第一个值last_value()over(partition by 列名1列名2 order by 列名1列名2)是求一组数据的最后一个值first_value 用法 select distinct a.date,a.name,first_value(date)over(partition by name order by date asc)as 每个人对应最早的date,first_value(date)over(partition by name order by date desc)as 每个人对应最晚的datefrom (select 张三as name,2021-04-11 as date union all select 李四as name,2021-04-09 as date union all select 赵四as name,2021-04-16 as date union all select 张三as name,2021-03-10as dateunion all select 李四as name,2020-01-01as date)a last_value 用法 select distinct a.date,a.name,last_value(date)over(partition by name order by date asc)as 每个人对应最晚的datefrom (select 张三as name,2021-04-11 as date union all select 李四as name,2021-04-09 as date union all select 赵四as name,2021-04-16 as date union all select 张三as name,2021-03-10as dateunion all select 李四as name,2020-01-01as date)a 可以看到使用 last_value 函数求每个人最后一个日期结果并不是想要的。那该怎么办呢查询该函数的具体用法发现 last_value() 默认的统计范围是”rows between unbounded preceding and current row【无界的前面行和当前行之间】” 怎么理解呢见下 rows between unbounded preceding and current row,可以这么理解: x∈(-∞,X)rows between unbounded preceding and unbounded following, x∈(-∞, ∞)rows between current row and unbounded following, x∈(X, ∞) last_value() 默认是升序如果限制了是降序则等同于 first_value() 升序 select distinct a.date,a.name,last_value(date)over(partition by name order by date rows between unbounded preceding and current row)as (-∞,X),last_value(date)over(partition by name order by date rows between unbounded preceding and unbounded following)as (-∞, ∞),last_value(date)over(partition by name order by date rows between current row and unbounded following)as (X, ∞)from (select 张三as name,2021-04-11 as date union all select 李四as name,2021-04-09 as date union all select 赵四as name,2021-04-16 as date union all select 张三as name,2021-03-10as dateunion all select 李四as name,2020-01-01as date)a