Hive常用窗口函数

2023-11-07

一、概述

1、定义

窗口函数是一组特殊函数

  • 扫描多个输入行来计算每个输出值,为每行数据生成一行结构
  • 可以通过窗口函数来实现复杂的计算和聚合
  • 按功能可划分为:序列(排序),聚合,分析

2、语法

function (arg1,..., arg n) over ([partition by <...>] [order by <....>] [<window_clause>])
  • partition by类似于group by,未指定则按整个结果集
  • 只有指定order by子句之后才能进行窗口定义
  • 可同时使用多个窗口函数
  • 过滤窗口函数计算结果必须在外面一层

3、演示数据

创建employee_contract
其字段如下:

+---------------+-----------------------------+----------+--+
|   col_name    |          data_type          | comment  |
+---------------+-----------------------------+----------+--+
| name          | string                      |          |
| work_place    | array<string>               |          |
| sex_age       | struct<sex:string,age:int>  |          |
| skills_score  | map<string,int>             |          |
| depart_title  | map<string,array<string>>   |          |
+---------------+-----------------------------+----------+--+

表中数据如下:

+-------------------------+-------------------------------+----------------------------+---------------------------------+----------------------------------------+--+
| employee_external.name  | employee_external.work_place  | employee_external.sex_age  | employee_external.skills_score  |     employee_external.depart_title     |
+-------------------------+-------------------------------+----------------------------+---------------------------------+----------------------------------------+--+
| Michael                 | ["Montreal","Toronto"]        | {"sex":"Male","age":30}    | {"DB":80}                       | {"Product":["Developer","Lead"]}       |
| Will                    | ["Montreal"]                  | {"sex":"Male","age":35}    | {"Perl":85}                     | {"Product":["Lead"],"Test":["Lead"]}   |
| Shelley                 | ["New York"]                  | {"sex":"Female","age":27}  | {"Python":80}                   | {"Test":["Lead"],"COE":["Architect"]}  |
| Lucy                    | ["Vancouver"]                 | {"sex":"Female","age":57}  | {"Sales":89,"HR":94}            | {"Sales":["Lead"]}                     |
+-------------------------+-------------------------------+----------------------------+---------------------------------+----------------------------------------+--+

二、窗口函数 - 序列

1、row_number()

对所有数值输出不同的序号,序号唯一连续

(1)给所有员工薪资排序,从低到高,针对所有员工

select name,dept_num,salary,
row_number() over(order by salary) as rn
from employee_contract;

运行结果如下:

+----------+-----------+---------+-----+--+
|   name   | dept_num  | salary  | rn  |
+----------+-----------+---------+-----+--+
| Wendy    | 1000      | 4000    | 1   |
| Will     | 1000      | 4000    | 2   |
| Lily     | 1001      | 5000    | 3   |
| Michael  | 1000      | 5000    | 4   |
| Yun      | 1002      | 5500    | 5   |
| Lucy     | 1000      | 5500    | 6   |
| Jess     | 1001      | 6000    | 7   |
| Mike     | 1001      | 6400    | 8   |
| Steven   | 1000      | 6400    | 9   |
| Wei      | 1002      | 7000    | 10  |
| Richard  | 1002      | 8000    | 11  |
+----------+-----------+---------+-----+--+

(2)按部门对每个员工薪资排序

select name,dept_num,salary,
row_number() over(partition by dept_num order by salary) as rn
from employee_contract;

运行结果如下:

+----------+-----------+---------+-----+--+
|   name   | dept_num  | salary  | rn  |
+----------+-----------+---------+-----+--+
| Yun      | 1002      | 5500    | 1   |
| Wei      | 1002      | 7000    | 2   |
| Richard  | 1002      | 8000    | 3   |
| Wendy    | 1000      | 4000    | 1   |
| Will     | 1000      | 4000    | 2   |
| Michael  | 1000      | 5000    | 3   |
| Lucy     | 1000      | 5500    | 4   |
| Steven   | 1000      | 6400    | 5   |
| Lily     | 1001      | 5000    | 1   |
| Jess     | 1001      | 6000    | 2   |
| Mike     | 1001      | 6400    | 3   |
+----------+-----------+---------+-----+--+

2、rank()

对相同数值,输出相同的序号,下一个序号跳过(1,1,3)

(1)给所有员工薪资排序,从低到高,针对所有员工

select name,dept_num,salary,
rank() over(order by salary) as rn
from employee_contract;

运行结果如下:

+----------+-----------+---------+-----+--+
|   name   | dept_num  | salary  | rn  |
+----------+-----------+---------+-----+--+
| Wendy    | 1000      | 4000    | 1   |
| Will     | 1000      | 4000    | 1   |
| Lily     | 1001      | 5000    | 3   |
| Michael  | 1000      | 5000    | 3   |
| Yun      | 1002      | 5500    | 5   |
| Lucy     | 1000      | 5500    | 5   |
| Jess     | 1001      | 6000    | 7   |
| Mike     | 1001      | 6400    | 8   |
| Steven   | 1000      | 6400    | 8   |
| Wei      | 1002      | 7000    | 10  |
| Richard  | 1002      | 8000    | 11  |
+----------+-----------+---------+-----+--+

3、dense_rank()

对相同数值,输出相同的序号,下一个序号连续(1,1,2)

(1)给所有员工薪资排序,从低到高,针对所有员工

select name,dept_num,salary,
dense_rank() over(order by salary) as rn
from employee_contract;

运行结果如下:

+----------+-----------+---------+-----+--+
|   name   | dept_num  | salary  | rn  |
+----------+-----------+---------+-----+--+
| Wendy    | 1000      | 4000    | 1   |
| Will     | 1000      | 4000    | 1   |
| Lily     | 1001      | 5000    | 2   |
| Michael  | 1000      | 5000    | 2   |
| Yun      | 1002      | 5500    | 3   |
| Lucy     | 1000      | 5500    | 3   |
| Jess     | 1001      | 6000    | 4   |
| Mike     | 1001      | 6400    | 5   |
| Steven   | 1000      | 6400    | 5   |
| Wei      | 1002      | 7000    | 6   |
| Richard  | 1002      | 8000    | 7   |
+----------+-----------+---------+-----+--+

(2)按部门分组,获取每个部门薪资最低的员工

select name,dept_num,salary from
(select name,dept_num,salary,
dense_rank() over(partition by dept_num order by salary) as rn
from employee_contract) t
where t.rn=1;

运行结果如下:

+--------+-----------+---------+--+
|  name  | dept_num  | salary  |
+--------+-----------+---------+--+
| Yun    | 1002      | 5500    |
| Wendy  | 1000      | 4000    |
| Will   | 1000      | 4000    |
| Lily   | 1001      | 5000    |
+--------+-----------+---------+--+

4、ntile(n)

将有序的数据集合平均分配到n个桶中, 将桶号分配给每一行,根据桶号,选取前或后n分之几的数据

(1)分桶查询

select name,dept_num,salary,
ntile(2) over(partition by dept_num order by salary)
as nlite
from employee_contract;

运行结果如下:

+----------+-----------+---------+--------+--+
|   name   | dept_num  | salary  | nlite  |
+----------+-----------+---------+--------+--+
| Yun      | 1002      | 5500    | 1      |
| Wei      | 1002      | 7000    | 1      |
| Richard  | 1002      | 8000    | 2      |
| Wendy    | 1000      | 4000    | 1      |
| Will     | 1000      | 4000    | 1      |
| Michael  | 1000      | 5000    | 1      |
| Lucy     | 1000      | 5500    | 2      |
| Steven   | 1000      | 6400    | 2      |
| Lily     | 1001      | 5000    | 1      |
| Jess     | 1001      | 6000    | 1      |
| Mike     | 1001      | 6400    | 2      |
+----------+-----------+---------+--------+--+

5、percent_rank()

(目前排名- 1)/(总行数- 1),值相对于一组值的百分比排名,即排名前百分比

(1)查询工资排名百分比

select name,dept_num,salary,
percent_rank() over(order by salary)
as pr
from employee_contract;

运行结果如下:

+----------+-----------+---------+------+--+
|   name   | dept_num  | salary  |  pr  |
+----------+-----------+---------+------+--+
| Wendy    | 1000      | 4000    | 0.0  |
| Will     | 1000      | 4000    | 0.0  |
| Lily     | 1001      | 5000    | 0.2  |
| Michael  | 1000      | 5000    | 0.2  |
| Yun      | 1002      | 5500    | 0.4  |
| Lucy     | 1000      | 5500    | 0.4  |
| Jess     | 1001      | 6000    | 0.6  |
| Mike     | 1001      | 6400    | 0.7  |
| Steven   | 1000      | 6400    | 0.7  |
| Wei      | 1002      | 7000    | 0.9  |
| Richard  | 1002      | 8000    | 1.0  |
+----------+-----------+---------+------+--+

三、窗口函数 - 聚合

1、count()

计数,可以和distinct一起用

(1)统计每个部门人数

select name,dept_num,salary,
count(*) over(partition by dept_num) as rc
from employee_contract;

运行结果如下:

+----------+-----------+---------+-----+--+
|   name   | dept_num  | salary  | rc  |
+----------+-----------+---------+-----+--+
| Lucy     | 1000      | 5500    | 5   |
| Steven   | 1000      | 6400    | 5   |
| Wendy    | 1000      | 4000    | 5   |
| Will     | 1000      | 4000    | 5   |
| Michael  | 1000      | 5000    | 5   |
| Mike     | 1001      | 6400    | 3   |
| Jess     | 1001      | 6000    | 3   |
| Lily     | 1001      | 5000    | 3   |
| Richard  | 1002      | 8000    | 3   |
| Yun      | 1002      | 5500    | 3   |
| Wei      | 1002      | 7000    | 3   |
+----------+-----------+---------+-----+--+

2、sum()

求和

(1)求每个部门的工资总和

select name,dept_num,salary,
sum(salary) over(partition by dept_num order by salary) as sum_salary
from employee_contract;

运行结果如下:

+----------+-----------+---------+-------------+--+
|   name   | dept_num  | salary  | sum_salary  |
+----------+-----------+---------+-------------+--+
| Wendy    | 1000      | 4000    | 8000        |
| Will     | 1000      | 4000    | 8000        |
| Michael  | 1000      | 5000    | 13000       |
| Lucy     | 1000      | 5500    | 18500       |
| Steven   | 1000      | 6400    | 24900       |
| Lily     | 1001      | 5000    | 5000        |
| Jess     | 1001      | 6000    | 11000       |
| Mike     | 1001      | 6400    | 17400       |
| Yun      | 1002      | 5500    | 5500        |
| Wei      | 1002      | 7000    | 12500       |
| Richard  | 1002      | 8000    | 20500       |
+----------+-----------+---------+-------------+--+

(2)求所有人工资总和

select name,dept_num,salary,
sum(salary) over(order by salary) as sum_salary
from employee_contract;

运行结果如下:

+----------+-----------+---------+-------------+--+
|   name   | dept_num  | salary  | sum_salary  |
+----------+-----------+---------+-------------+--+
| Wendy    | 1000      | 4000    | 8000        |
| Will     | 1000      | 4000    | 8000        |
| Lily     | 1001      | 5000    | 18000       |
| Michael  | 1000      | 5000    | 18000       |
| Yun      | 1002      | 5500    | 29000       |
| Lucy     | 1000      | 5500    | 29000       |
| Jess     | 1001      | 6000    | 35000       |
| Mike     | 1001      | 6400    | 47800       |
| Steven   | 1000      | 6400    | 47800       |
| Wei      | 1002      | 7000    | 54800       |
| Richard  | 1002      | 8000    | 62800       |
+----------+-----------+---------+-------------+--+

3、avg()、max()、min()

平均值、最大值、最小值

select name,dept_num,salary,
avg(salary) over(partition by dept_num) as avgDept,
min(salary) over(partition by dept_num) as minDept,
max(salary) over(partition by dept_num) as maxDept
from employee_contract;

运行结果如下:

+----------+-----------+---------+--------------------+----------+----------+--+
|   name   | dept_num  | salary  |      avgdept       | mindept  | maxdept  |
+----------+-----------+---------+--------------------+----------+----------+--+
| Lucy     | 1000      | 5500    | 4980.0             | 4000     | 6400     |
| Steven   | 1000      | 6400    | 4980.0             | 4000     | 6400     |
| Wendy    | 1000      | 4000    | 4980.0             | 4000     | 6400     |
| Will     | 1000      | 4000    | 4980.0             | 4000     | 6400     |
| Michael  | 1000      | 5000    | 4980.0             | 4000     | 6400     |
| Mike     | 1001      | 6400    | 5800.0             | 5000     | 6400     |
| Jess     | 1001      | 6000    | 5800.0             | 5000     | 6400     |
| Lily     | 1001      | 5000    | 5800.0             | 5000     | 6400     |
| Richard  | 1002      | 8000    | 6833.333333333333  | 5500     | 8000     |
| Yun      | 1002      | 5500    | 6833.333333333333  | 5500     | 8000     |
| Wei      | 1002      | 7000    | 6833.333333333333  | 5500     | 8000     |
+----------+-----------+---------+--------------------+----------+----------+--+

四、窗口函数 - 分析

1、cume_dist

小于等于当前值的行数/分组内总行数

(1)求每个部门中每个人的薪资排名比

select name,dept_num,salary,
cume_dist() over(partition by dept_num
order by salary) as cd
from employee_contract;

运行结果如下:

+----------+-----------+---------+---------------------+--+
|   name   | dept_num  | salary  |         cd          |
+----------+-----------+---------+---------------------+--+
| Wendy    | 1000      | 4000    | 0.4                 |
| Will     | 1000      | 4000    | 0.4                 |
| Michael  | 1000      | 5000    | 0.6                 |
| Lucy     | 1000      | 5500    | 0.8                 |
| Steven   | 1000      | 6400    | 1.0                 |
| Lily     | 1001      | 5000    | 0.3333333333333333  |
| Jess     | 1001      | 6000    | 0.6666666666666666  |
| Mike     | 1001      | 6400    | 1.0                 |
| Yun      | 1002      | 5500    | 0.3333333333333333  |
| Wei      | 1002      | 7000    | 0.6666666666666666  |
| Richard  | 1002      | 8000    | 1.0                 |
+----------+-----------+---------+---------------------+--+

2、lead/lag(col,n)

某一列进行往前/后第n行值(n可选,默认为1)

(1)以部门分组、员工薪资排序,求当前员工的后面一位员工的薪资,每个部门排名最后一个用默认值 NULL 表示

select name,dept_num,salary,
lead(salary,1) over(partition by dept_num order by salary) as lead
from employee_contract;

运行结果如下:

+----------+-----------+---------+-------+--+
|   name   | dept_num  | salary  | lead  |
+----------+-----------+---------+-------+--+
| Wendy    | 1000      | 4000    | 4000  |
| Will     | 1000      | 4000    | 5000  |
| Michael  | 1000      | 5000    | 5500  |
| Lucy     | 1000      | 5500    | 6400  |
| Steven   | 1000      | 6400    | NULL  |
| Lily     | 1001      | 5000    | 6000  |
| Jess     | 1001      | 6000    | 6400  |
| Mike     | 1001      | 6400    | NULL  |
| Yun      | 1002      | 5500    | 7000  |
| Wei      | 1002      | 7000    | 8000  |
| Richard  | 1002      | 8000    | NULL  |
+----------+-----------+---------+-------+--+

(2)以部门分组、员工薪资排序,求当前员工的后面一位员工的薪资,每个部门排名最后一个用指定 0 表示

select name,dept_num,salary,
lead(salary,1,0) over(partition by dept_num order by salary) as lead
from employee_contract;

运行结果如下:

+----------+-----------+---------+-------+--+
|   name   | dept_num  | salary  | lead  |
+----------+-----------+---------+-------+--+
| Wendy    | 1000      | 4000    | 4000  |
| Will     | 1000      | 4000    | 5000  |
| Michael  | 1000      | 5000    | 5500  |
| Lucy     | 1000      | 5500    | 6400  |
| Steven   | 1000      | 6400    | 0     |
| Lily     | 1001      | 5000    | 6000  |
| Jess     | 1001      | 6000    | 6400  |
| Mike     | 1001      | 6400    | 0     |
| Yun      | 1002      | 5500    | 7000  |
| Wei      | 1002      | 7000    | 8000  |
| Richard  | 1002      | 8000    | 0     |
+----------+-----------+---------+-------+--+

(3)以部门分组、员工薪资排序,求当前员工的前面一位员工的薪资,每个部门排名第一个员工用默认值 NULL 表示

select name,dept_num,salary,
lag(salary,1) over(partition by dept_num order by salary) as lag
from employee_contract;

运行结果如下:

+----------+-----------+---------+-------+--+
|   name   | dept_num  | salary  |  lag  |
+----------+-----------+---------+-------+--+
| Wendy    | 1000      | 4000    | NULL  |
| Will     | 1000      | 4000    | 4000  |
| Michael  | 1000      | 5000    | 4000  |
| Lucy     | 1000      | 5500    | 5000  |
| Steven   | 1000      | 6400    | 5500  |
| Lily     | 1001      | 5000    | NULL  |
| Jess     | 1001      | 6000    | 5000  |
| Mike     | 1001      | 6400    | 6000  |
| Yun      | 1002      | 5500    | NULL  |
| Wei      | 1002      | 7000    | 5500  |
| Richard  | 1002      | 8000    | 7000  |
+----------+-----------+---------+-------+--+

(4)以部门分组、员工薪资排序,求当前员工的前面一位员工的薪资,每个部门排名第一个员工用指定值 0 表示

select name,dept_num,salary,
lag(salary,1,0) over(partition by dept_num order by salary) as lag
from employee_contract;

运行结果如下:

+----------+-----------+---------+-------+--+
|   name   | dept_num  | salary  |  lag  |
+----------+-----------+---------+-------+--+
| Wendy    | 1000      | 4000    | 0     |
| Will     | 1000      | 4000    | 4000  |
| Michael  | 1000      | 5000    | 4000  |
| Lucy     | 1000      | 5500    | 5000  |
| Steven   | 1000      | 6400    | 5500  |
| Lily     | 1001      | 5000    | 0     |
| Jess     | 1001      | 6000    | 5000  |
| Mike     | 1001      | 6400    | 6000  |
| Yun      | 1002      | 5500    | 0     |
| Wei      | 1002      | 7000    | 5500  |
| Richard  | 1002      | 8000    | 7000  |
+----------+-----------+---------+-------+--+

3、firsvt_value、last_value

对该列到目前为止的首个值、最后一个值

select name,dept_num,salary,
first_value(salary) over(partition by dept_num order by salary) as fv,
last_value(salary) over(partition by dept_num order by salary) as lv
from employee_contract;

运行结果如下:

+----------+-----------+---------+-------+-------+--+
|   name   | dept_num  | salary  |  fv   |  lv   |
+----------+-----------+---------+-------+-------+--+
| Wendy    | 1000      | 4000    | 4000  | 4000  |
| Will     | 1000      | 4000    | 4000  | 4000  |
| Michael  | 1000      | 5000    | 4000  | 5000  |
| Lucy     | 1000      | 5500    | 4000  | 5500  |
| Steven   | 1000      | 6400    | 4000  | 6400  |
| Lily     | 1001      | 5000    | 5000  | 5000  |
| Jess     | 1001      | 6000    | 5000  | 6000  |
| Mike     | 1001      | 6400    | 5000  | 6400  |
| Yun      | 1002      | 5500    | 5500  | 5500  |
| Wei      | 1002      | 7000    | 5500  | 7000  |
| Richard  | 1002      | 8000    | 5500  | 8000  |
+----------+-----------+---------+-------+-------+--+

五、窗口函数 - 窗口子句

1、含义

窗口子句由[<window_clause>]子句描述

  • 用于进一步细分结果并应用分析函数
  • rank、ntile、dense_rank、cume_dist、percent_rank、lead、lag和row_number函数不支持与窗口子句一起使用
  • 支持两类窗口子句
    • 行类型窗口
    • 范围类型窗口

2、行窗口

(1)根据当前行之前或之后的行号确定的窗口
在这里插入图片描述
(2)语法:

rows between <start_expr> and <end_expr>

(3)<start_expr>取值

取值 意义
unbounded preceding 窗口起始位置(分组第一行)
current row 当前行
n preceding/following 当前行之前/之后n行

(4)<end_expr>可以为下列值

取值 意义
unbounded following 窗口结束位置(分组最后一行)
current row 当前行
n preceding/following 当前行之前/之后n行

示例:

select
name, dept_num as dept, salary as sal,
max(salary) over (partition by dept_num order by name rows between 2 preceding and current row) win1,
max(salary) over (partition by dept_num order by name rows between 2 preceding and unbounded following) win2,
max(salary) over (partition by dept_num order by name rows between 1 preceding and 2 following) win3,
max(salary) over (partition by dept_num order by name rows between 2 preceding and 1 preceding) win4,
max(salary) over (partition by dept_num order by name rows between 1 following and 2 following) win5,
max(salary) over (partition by dept_num order by name rows between current row and current row) win6,
max(salary) over (partition by dept_num order by name rows between current row and 1 following) win7,
max(salary) over (partition by dept_num order by name rows between current row and unbounded following) win8,
max(salary) over (partition by dept_num order by name rows between unbounded preceding and current row) win9,
max(salary) over (partition by dept_num order by name rows between unbounded preceding and 1 following) win10,
max(salary) over (partition by dept_num order by name rows between unbounded preceding and unbounded following) win11,
max(salary) over (partition by dept_num order by name rows 2 preceding) win12
from employee_contract  order by dept, name;

运行结果如下:

+----------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+--------+--------+--------+--+
|   name   | dept  |  sal  | win1  | win2  | win3  | win4  | win5  | win6  | win7  | win8  | win9  | win10  | win11  | win12  |
+----------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+--------+--------+--------+--+
| Lucy     | 1000  | 5500  | 5500  | 6400  | 6400  | NULL  | 6400  | 5500  | 5500  | 6400  | 5500  | 5500   | 6400   | 5500   |
| Michael  | 1000  | 5000  | 5500  | 6400  | 6400  | 5500  | 6400  | 5000  | 6400  | 6400  | 5500  | 6400   | 6400   | 5500   |
| Steven   | 1000  | 6400  | 6400  | 6400  | 6400  | 5500  | 4000  | 6400  | 6400  | 6400  | 6400  | 6400   | 6400   | 6400   |
| Wendy    | 1000  | 4000  | 6400  | 6400  | 6400  | 6400  | 4000  | 4000  | 4000  | 4000  | 6400  | 6400   | 6400   | 6400   |
| Will     | 1000  | 4000  | 6400  | 6400  | 4000  | 6400  | NULL  | 4000  | 4000  | 4000  | 6400  | 6400   | 6400   | 6400   |
| Jess     | 1001  | 6000  | 6000  | 6400  | 6400  | NULL  | 6400  | 6000  | 6000  | 6400  | 6000  | 6000   | 6400   | 6000   |
| Lily     | 1001  | 5000  | 6000  | 6400  | 6400  | 6000  | 6400  | 5000  | 6400  | 6400  | 6000  | 6400   | 6400   | 6000   |
| Mike     | 1001  | 6400  | 6400  | 6400  | 6400  | 6000  | NULL  | 6400  | 6400  | 6400  | 6400  | 6400   | 6400   | 6400   |
| Richard  | 1002  | 8000  | 8000  | 8000  | 8000  | NULL  | 7000  | 8000  | 8000  | 8000  | 8000  | 8000   | 8000   | 8000   |
| Wei      | 1002  | 7000  | 8000  | 8000  | 8000  | 8000  | 5500  | 7000  | 7000  | 7000  | 8000  | 8000   | 8000   | 8000   |
| Yun      | 1002  | 5500  | 8000  | 8000  | 7000  | 8000  | NULL  | 5500  | 5500  | 5500  | 8000  | 8000   | 8000   | 8000   |
+----------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+--------+--------+--------+--+

3、范围窗口

范围窗口是取分组内的值在指定范围区间内的行

  • 该范围值/区间必须是数字或日期类型
  • 目前只支持一个order by列

示例:

select name, dept_num as dept, salary as sal,
max(salary) over (partition by dept_num order by name rows between 2 preceding and current row) win1,
salary - 1000 as sal_r_start,salary as sal_r_end,
max(salary) over (partition by dept_num
order by name range between 1000 preceding and current row) win13
from employee_contract order by dept, name;

运行结果如下:

+----------+-------+-------+-------+--------------+------------+--------+--+
|   name   | dept  |  sal  | win1  | sal_r_start  | sal_r_end  | win13  |
+----------+-------+-------+-------+--------------+------------+--------+--+
| Lucy     | 1000  | 5500  | 5500  | 4500         | 5500       | 5500   |
| Michael  | 1000  | 5000  | 5500  | 4000         | 5000       | 5000   |
| Steven   | 1000  | 6400  | 6400  | 5400         | 6400       | 6400   |
| Wendy    | 1000  | 4000  | 6400  | 3000         | 4000       | 4000   |
| Will     | 1000  | 4000  | 6400  | 3000         | 4000       | 4000   |
| Jess     | 1001  | 6000  | 6000  | 5000         | 6000       | 6000   |
| Lily     | 1001  | 5000  | 6000  | 4000         | 5000       | 5000   |
| Mike     | 1001  | 6400  | 6400  | 5400         | 6400       | 6400   |
| Richard  | 1002  | 8000  | 8000  | 7000         | 8000       | 8000   |
| Wei      | 1002  | 7000  | 8000  | 6000         | 7000       | 7000   |
| Yun      | 1002  | 5500  | 8000  | 4500         | 5500       | 5500   |
+----------+-------+-------+-------+--------------+------------+--------+--+
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Hive常用窗口函数 的相关文章

随机推荐

  • 【超详细】SSM框架项目实战

    相关资料网盘链接 CRM客户管理系统资料 提取码 0u04 P1 CRM阶段简介 web项目开发 如何分析 设计 编码 测试 形成编程思想和编程习惯 P2 CRM的技术架构 视图层 View 展示数据 跟用户交互 html css js j
  • Unity3d打开的时候,卡在loading界面白屏的解决方法

    本文首发于 洪流学堂 公众号 洪流学堂 让你快人几步 你好 我是你的技术探路者郑洪智 你可以叫我大智 vx zhz11235 Unity3d打开的时候 当遇见卡Loading的时候 可以看看Editor log C Users
  • 12.6 包的声明和访问

    包的概念 java的包 其实就是我们电脑系统中的文件夹 包里存放的是类文件 当类文件很多的时候 通常我们会采用多个包进行存放管理他们 这种方式称为分包管理 在项目中 我们将相同功能的类放到一个包中 方便管理 并且日常项目的分工也是以包作为边
  • 使用cmake工具多文件编译

    使用cmake工具多文件编译 创建CMakeLists txt project PEOPLE add executable my cmake people main cpp people cpp ctrl shift p 为了生成build
  • 多线程(七)线程池

    线程池 又是一个池 我们已经见识过很多池了 数据库连接池 字符串常量池 那我们这个线程池又是个啥呢 我们提前将线程准备好 需要用的时候直接取 不需要用的时候 在直接还回去 这样就不需要去从系统中申请了 这样做 最大的好处就是减少每次启动 销
  • 十大排序算法-----归并排序

    归并排序 原理 归并排序是一种概念上最简单的排序算法 归并排序是基于分治法的 归并排序将待排序的元素序列分成两个长度相等的子序列 为每一个子序列排序 然后再将他们合并成一个子序列 合并两个子序列的过程也就是两路归并 算法基本步骤 1 申请空
  • 从0.3开始搭建LeGO-LOAM+VLP雷达+小车实时建图(保姆级教程,小白踩坑日记)

    背景 SLAM小白 因为项目需要花了两天时间编译代码 连接雷达实现了交互 踩了很多坑 简单记录一下 让后面感兴趣的朋友少走点弯路 肯定有很多不专业的 错误的地方 还请大家不吝赐教 噗通 也可以见知乎 https zhuanlan zhihu
  • 实战中绕过disable_functions执行命令

    前言 前几天看到有大佬提到一种小型贷款网站 这种贷款网站从账号的注册到借款的流程都显得很随便 仿佛巴不得直接无条件借钱给你似的 充满 诈骗 的气息 任意文件上传 看着充满暗示的提示语 我们仿照受害者的思路点击借款 随意填写借款金额后 会让我
  • node.js入门笔记(五)——express框架、路由、模板引擎

    node js入门笔记 五 1 特殊依赖 2 express的路由机制 3 express中的路由功能 3 1Router的基本使用 3 2Router的参数传递 3 2Router的请求种类 3 controller的预使用 4 expr
  • 如何解决Dynamics 365的错误:用户身份验证无效,MSIS0006

    关注本人微信和易信公众号 微软动态CRM专家罗勇 回复246或者20170312可方便获取本文 同时可以在第一间得到我发布的最新的博文信息 follow me 我的网站是 www luoyong me 这两天突然访问不了我的部署在Azure
  • 弹性数据库连接池探活策略调研(二)——Druid

    前言 在上一篇文章中 我们介绍了弹性数据库连接失效的背景 并探讨了HikariCP连接池探活策略的相关内容 在本文中 我们将会继续探讨另一个线上常用的连接池 Druid 并为您介绍如何在使用Druid时实现最佳实践的弹性数据库连接池探活策略
  • 每日一题:简单分数统计

    简单分数统计 题目 Daimayuan Online Judge 发现样例输出的是id和成绩 那么就写一个包含这两个变量的结构体来储存它们 另外 再写一个结构体来储存题目名称和分数 目的是使两者联系起来 找到题目名称就能知道对应的分数 AC
  • 学习感悟(基于轻量化卷积神经网络的人脸表情识别方法)

    轻量化卷积神经网络的人脸表情识别方法 文献重点 主要研究方法 感悟 文献重点 主要研究方法 感悟 1 文献重点 面部表情识别是生物信息识别 模式识别 人机交互与人工智能等领域的重要研究课题 深度神经网络的兴起为高精度面部表情识别的研究提供了
  • 解决json object转string,value值存在特殊符号,无法解析问题

    昨天在JSON stringify 转数组的时候 发现一直报错 最终确定原因为string中的空格在html显示的时候 会自动加上 nbsp 知道了问题所在 下面讲解如何解决问题 我们在取数据时 用HTMLDecode2 方法过滤下特殊字符
  • Mysql 中 1062 –Duplicate entry '1' for key 'PRIMARY'

    我遇到的这种问题 就是在数据库中插入数据时 主键重复了 换个新的主键就可以了 比如之前有个主键是1 新添加了一条数据主键也设置成1了
  • easyexcel工具包使用报错:NoClassDeffoundError

    错误日志 easyexcel操作excel pom导包失败 引入外部jar包 处理异常报错 报错原因 easyexcel缺失关键依赖包 解决 修改maven配置文件 加入alibaba镜像地址 重新加载包 问题解决
  • GIS坐标系统

    最新在看GIS的理论知识 坐标系统这块比较抽象 B站上搜到到一个博主的视频 对这块讲解的比较通俗易懂 这里记录一下 地理坐标系统 地理坐标系统是地球表面空间要素的定位参照系统 地理坐标系统是由经度和维度定义的 经度和维度都是用角度量的 经度
  • oracle ebs应付模块表,oracle ebs 11i 数据表大全(总帐、应收、应付等各模块) 免费...

    OWNER OBJECT NAME OBJECT TYPE CREATED PO PO LOCATION T ABLE TABLE PO PO VENDOR S TABLE PO PO LINE LOCA PO PO VENDORS T A
  • 大厂怎么做

    作者 郑东博士 快手 推荐算法技术总监 整理 DataFunTalk 大家好 这里是 NewBeeNLP 快手是中国领先的短视频和直播社区 拥有超过3亿的DAU和丰富的社交数据 快手秉承的价值观是真实 多元 美好 有用 致力于提高每一个用户
  • Hive常用窗口函数

    目录 一 概述 1 定义 2 语法 3 演示数据 二 窗口函数 序列 1 row number 2 rank 3 dense rank 4 ntile n 5 percent rank 三 窗口函数 聚合 1 count 2 sum 3 a