当前位置: 首页 > news >正文

MySQL入门篇-MySQL高级窗口函数简介

备注:测试数据库版本为MySQL 8.0

这个blog我们来聊聊MySQL高级窗口函数
窗口函数在复杂查询以及数据仓库中应用得比较频繁
与sql打交道比较多的技术人员都需要掌握

如需要scott用户下建表及录入数据语句,可参考:
scott建表及录入数据sql脚本

 

分析函数有3个基本组成部分:
1.分区子句
2.排序子句
3.开窗子句

function1 (argument1,argument2,..argumentN)
over  w
window w as ([partition-by-clause] [order-by-clause] [windowing-clause])

窗口说明子句的语法:
默认的窗口子句是rows between unbounded preceding and current row。如果你没有显示声明窗口,就将会使用默认窗口。
并不是所有的分析函数都支持开窗子句

[rows | range] between <start expr> and [end expr]whereas
<start expr> is [unbounded preceding | current row | n preceding | n following]
<end expr> is [unbounded following | current row | n preceding | n following]

row_number、rank、dense_rank 

row_number语法:

row_number() over w
window w as (partition-clause order-by-clause)

row_number不支持开窗子句
rank、dense_rank语法同row_number语法

现在需要对分不同部门来看部门内的工资排名,且从大到小排列:

-- 可以看到deptno为30的员工工资有重复的,重复的工资为1250
-- row_number()  不关注重复的,直接排名,1-2-3-4-5-6
-- rank()        重复排名,会跳过,1-2-3-4-4-6
-- dense_rank()  重复排名,不跳过,1-2-3-4-4-5
select a.empno,a.ename,a.deptno,a.sal,row_number() over w as 'num',rank() over w as 'rank',dense_rank() over w  as 'dense_rank'from emp awindow w as (partition by a.deptno order by a.sal desc)
;
mysql> select a.empno,->        a.ename,->        a.deptno,->        a.sal,->        row_number() over w as 'num',->        rank() over w as 'rank',->        dense_rank() over w  as 'dense_rank'->   from emp a->   window w as (partition by a.deptno order by a.sal desc)-> ;
+-------+--------+--------+---------+-----+------+------------+
| empno | ename  | deptno | sal     | num | rank | dense_rank |
+-------+--------+--------+---------+-----+------+------------+
|  7839 | KING   |     10 | 5000.00 |   1 |    1 |          1 |
|  7782 | CLARK  |     10 | 2450.00 |   2 |    2 |          2 |
|  7934 | MILLER |     10 | 1300.00 |   3 |    3 |          3 |
|  7788 | SCOTT  |     20 | 3000.00 |   1 |    1 |          1 |
|  7902 | FORD   |     20 | 3000.00 |   2 |    1 |          1 |
|  7566 | JONES  |     20 | 2975.00 |   3 |    3 |          2 |
|  7876 | ADAMS  |     20 | 1100.00 |   4 |    4 |          3 |
|  7369 | SMITH  |     20 |  800.00 |   5 |    5 |          4 |
|  7698 | BLAKE  |     30 | 2850.00 |   1 |    1 |          1 |
|  7499 | ALLEN  |     30 | 1600.00 |   2 |    2 |          2 |
|  7844 | TURNER |     30 | 1500.00 |   3 |    3 |          3 |
|  7521 | WARD   |     30 | 1250.00 |   4 |    4 |          4 |
|  7654 | MARTIN |     30 | 1250.00 |   5 |    4 |          4 |
|  7900 | JAMES  |     30 |  950.00 |   6 |    6 |          5 |
+-------+--------+--------+---------+-----+------+------------+
14 rows in set (0.01 sec)

lag、lead

lag语法:

lag (expression, offset, default) over w
window w as  (partition-clause order-by-clause)

lag不支持开窗子句
lead同lag语法

-- 根据分组,取值上n条和下n条   如果是第一条或最后一条,就给个默认值
SELECT a.empno,a.deptno,a.hiredate,a.sal,lag(sal, 1, 0) over w as 'pre_sal',lead(sal, 1, 0) over w as 'next_sal',lag(sal, 2, 0) over w  as 'pre2_sal',lead(sal, 2, 0) over w as 'next_2sal'FROM emp awindow w  as (PARTITION BY a.deptno ORDER BY hiredate ASC)
;
mysql> SELECT a.empno,->        a.deptno,->        a.hiredate,->        a.sal,->        lag(sal, 1, 0) over w as 'pre_sal',->        lead(sal, 1, 0) over w as 'next_sal',->        lag(sal, 2, 0) over w  as 'pre2_sal',->        lead(sal, 2, 0) over w as 'next_2sal'->   FROM emp a->   window w  as (PARTITION BY a.deptno ORDER BY hiredate ASC)-> ;
+-------+--------+------------+---------+---------+----------+----------+-----------+
| empno | deptno | hiredate   | sal     | pre_sal | next_sal | pre2_sal | next_2sal |
+-------+--------+------------+---------+---------+----------+----------+-----------+
|  7782 |     10 | 1981-06-09 | 2450.00 |    0.00 |  5000.00 |     0.00 |   1300.00 |
|  7839 |     10 | 1981-11-17 | 5000.00 | 2450.00 |  1300.00 |     0.00 |      0.00 |
|  7934 |     10 | 1982-01-23 | 1300.00 | 5000.00 |     0.00 |  2450.00 |      0.00 |
|  7369 |     20 | 1980-12-17 |  800.00 |    0.00 |  2975.00 |     0.00 |   3000.00 |
|  7566 |     20 | 1981-04-02 | 2975.00 |  800.00 |  3000.00 |     0.00 |   3000.00 |
|  7902 |     20 | 1981-12-03 | 3000.00 | 2975.00 |  3000.00 |   800.00 |   1100.00 |
|  7788 |     20 | 1987-06-13 | 3000.00 | 3000.00 |  1100.00 |  2975.00 |      0.00 |
|  7876 |     20 | 1987-06-13 | 1100.00 | 3000.00 |     0.00 |  3000.00 |      0.00 |
|  7499 |     30 | 1981-02-20 | 1600.00 |    0.00 |  1250.00 |     0.00 |   2850.00 |
|  7521 |     30 | 1981-02-22 | 1250.00 | 1600.00 |  2850.00 |     0.00 |   1500.00 |
|  7698 |     30 | 1981-05-01 | 2850.00 | 1250.00 |  1500.00 |  1600.00 |   1250.00 |
|  7844 |     30 | 1981-09-08 | 1500.00 | 2850.00 |  1250.00 |  1250.00 |    950.00 |
|  7654 |     30 | 1981-09-28 | 1250.00 | 1500.00 |   950.00 |  2850.00 |      0.00 |
|  7900 |     30 | 1981-12-03 |  950.00 | 1250.00 |     0.00 |  1500.00 |      0.00 |
+-------+--------+------------+---------+---------+----------+----------+-----------+
14 rows in set (0.00 sec)
-- 没有比自己小我的我们设为AAA,没有比自己大的,我们设置为ZZZ
select deptno,ename,lag(ename, 1, 'AAA') over w as 'lower_name',lead(ename, 1, 'ZZZ') over w as 'higher_name'from emp
window w as(PARTITION BY deptno ORDER BY ename)
;-- 部门重复的话值输出第一行的部门编号  
select (case when deptno= lag(deptno,1)over w then null else deptno end) as 'deptno',ename,lag(ename, 1, 'AAA') over w  as 'lower_name',lead(ename, 1, 'ZZZ') over w as 'higher_name'from emp
window w  as (PARTITION BY deptno ORDER BY ename)
;
mysql> -- 没有比自己小我的我们设为AAA,没有比自己大的,我们设置为ZZZ
mysql> select deptno,->        ename,->        lag(ename, 1, 'AAA') over w as 'lower_name',->        lead(ename, 1, 'ZZZ') over w as 'higher_name'->   from emp-> window w as(PARTITION BY deptno ORDER BY ename)-> ;
+--------+--------+------------+-------------+
| deptno | ename  | lower_name | higher_name |
+--------+--------+------------+-------------+
|     10 | CLARK  | AAA        | KING        |
|     10 | KING   | CLARK      | MILLER      |
|     10 | MILLER | KING       | ZZZ         |
|     20 | ADAMS  | AAA        | FORD        |
|     20 | FORD   | ADAMS      | JONES       |
|     20 | JONES  | FORD       | SCOTT       |
|     20 | SCOTT  | JONES      | SMITH       |
|     20 | SMITH  | SCOTT      | ZZZ         |
|     30 | ALLEN  | AAA        | BLAKE       |
|     30 | BLAKE  | ALLEN      | JAMES       |
|     30 | JAMES  | BLAKE      | MARTIN      |
|     30 | MARTIN | JAMES      | TURNER      |
|     30 | TURNER | MARTIN     | WARD        |
|     30 | WARD   | TURNER     | ZZZ         |
+--------+--------+------------+-------------+
14 rows in set (0.00 sec)mysql>
mysql> -- 部门重复的话值输出第一行的部门编号
mysql> select (case when deptno= lag(deptno,1)over w then null else deptno end) as 'deptno',->         ename,->        lag(ename, 1, 'AAA') over w  as 'lower_name',->        lead(ename, 1, 'ZZZ') over w as 'higher_name'->   from emp-> window w  as (PARTITION BY deptno ORDER BY ename)-> ;
+--------+--------+------------+-------------+
| deptno | ename  | lower_name | higher_name |
+--------+--------+------------+-------------+
|     10 | CLARK  | AAA        | KING        |
|   NULL | KING   | CLARK      | MILLER      |
|   NULL | MILLER | KING       | ZZZ         |
|     20 | ADAMS  | AAA        | FORD        |
|   NULL | FORD   | ADAMS      | JONES       |
|   NULL | JONES  | FORD       | SCOTT       |
|   NULL | SCOTT  | JONES      | SMITH       |
|   NULL | SMITH  | SCOTT      | ZZZ         |
|     30 | ALLEN  | AAA        | BLAKE       |
|   NULL | BLAKE  | ALLEN      | JAMES       |
|   NULL | JAMES  | BLAKE      | MARTIN      |
|   NULL | MARTIN | JAMES      | TURNER      |
|   NULL | TURNER | MARTIN     | WARD        |
|   NULL | WARD   | TURNER     | ZZZ         |
+--------+--------+------------+-------------+
14 rows in set (0.00 sec)

first_value、last_value、nth_value

first_value、last_value语法:

first_value(expression) over w 
window w as  (partition-clause order-by-clause windowing-clause)
last_value(expression) over w
window w as  (partition-clause order-by-clause windowing-clause)

nth_value语法:

nth_value (measure, n) [ from first | from last ] [ respect nulls | ignore nulls ]
over  w
window w as  (partitioning-clause order-by-clause windowing-clause) 

/*
需求:求每个部门工资最高的和工资最低的以及工资第二高的
*/-- 默认不带开窗子句,从第一行到当前行
select a.empno,a.deptno,a.sal,first_value(a.sal)  over w as 'first',last_value(a.sal) over w as 'last',nth_value(a.sal,2) over w as 'top_2'from emp awindow w  as (partition by a.deptno order by sal)
;-- rows between unbounded preceding and current row  从第一行到当前行
select a.empno,a.deptno,a.sal,first_value(a.sal)  over w as 'first',last_value(a.sal) over w as 'last',nth_value(a.sal,2) over w as 'top_2'from emp awindow w  as (partition by a.deptno order by sal rows between unbounded preceding and current row)
;-- rows between unbounded preceding and unbounded following 从第一行到最后一行select a.empno,a.deptno,a.sal,first_value(a.sal)  over w as 'first',last_value(a.sal) over w as 'last',nth_value(a.sal,2) over w as 'top_2'from emp awindow w  as (partition by a.deptno order by sal rows between unbounded preceding and unbounded following)
; -- 1 preceding and 1 following   当前行的前一行到当前行的后一行 select a.empno,a.deptno,a.sal,first_value(a.sal)  over w as 'first',last_value(a.sal) over w as 'last',nth_value(a.sal,2) over w as 'top_2'from emp awindow w  as (partition by a.deptno order by sal rows between 1 preceding and 1 following)
; 
mysql> -- 默认不带开窗子句,从第一行到当前行
mysql> select a.empno,a.deptno,a.sal,->        first_value(a.sal)  over w as 'first',->        last_value(a.sal) over w as 'last',->        nth_value(a.sal,2) over w as 'top_2'->   from emp a->   window w  as (partition by a.deptno order by sal)-> ;
+-------+--------+---------+---------+---------+---------+
| empno | deptno | sal     | first   | last    | top_2   |
+-------+--------+---------+---------+---------+---------+
|  7934 |     10 | 1300.00 | 1300.00 | 1300.00 |    NULL |
|  7782 |     10 | 2450.00 | 1300.00 | 2450.00 | 2450.00 |
|  7839 |     10 | 5000.00 | 1300.00 | 5000.00 | 2450.00 |
|  7369 |     20 |  800.00 |  800.00 |  800.00 |    NULL |
|  7876 |     20 | 1100.00 |  800.00 | 1100.00 | 1100.00 |
|  7566 |     20 | 2975.00 |  800.00 | 2975.00 | 1100.00 |
|  7788 |     20 | 3000.00 |  800.00 | 3000.00 | 1100.00 |
|  7902 |     20 | 3000.00 |  800.00 | 3000.00 | 1100.00 |
|  7900 |     30 |  950.00 |  950.00 |  950.00 |    NULL |
|  7521 |     30 | 1250.00 |  950.00 | 1250.00 | 1250.00 |
|  7654 |     30 | 1250.00 |  950.00 | 1250.00 | 1250.00 |
|  7844 |     30 | 1500.00 |  950.00 | 1500.00 | 1250.00 |
|  7499 |     30 | 1600.00 |  950.00 | 1600.00 | 1250.00 |
|  7698 |     30 | 2850.00 |  950.00 | 2850.00 | 1250.00 |
+-------+--------+---------+---------+---------+---------+
14 rows in set (0.00 sec)mysql>
mysql> -- rows between unbounded preceding and current row  从第一行到当前行
mysql> select a.empno,a.deptno,a.sal,->        first_value(a.sal)  over w as 'first',->        last_value(a.sal) over w as 'last',->        nth_value(a.sal,2) over w as 'top_2'->   from emp a->    window w  as (partition by a.deptno order by sal rows between unbounded preceding and current row)-> ;
+-------+--------+---------+---------+---------+---------+
| empno | deptno | sal     | first   | last    | top_2   |
+-------+--------+---------+---------+---------+---------+
|  7934 |     10 | 1300.00 | 1300.00 | 1300.00 |    NULL |
|  7782 |     10 | 2450.00 | 1300.00 | 2450.00 | 2450.00 |
|  7839 |     10 | 5000.00 | 1300.00 | 5000.00 | 2450.00 |
|  7369 |     20 |  800.00 |  800.00 |  800.00 |    NULL |
|  7876 |     20 | 1100.00 |  800.00 | 1100.00 | 1100.00 |
|  7566 |     20 | 2975.00 |  800.00 | 2975.00 | 1100.00 |
|  7788 |     20 | 3000.00 |  800.00 | 3000.00 | 1100.00 |
|  7902 |     20 | 3000.00 |  800.00 | 3000.00 | 1100.00 |
|  7900 |     30 |  950.00 |  950.00 |  950.00 |    NULL |
|  7521 |     30 | 1250.00 |  950.00 | 1250.00 | 1250.00 |
|  7654 |     30 | 1250.00 |  950.00 | 1250.00 | 1250.00 |
|  7844 |     30 | 1500.00 |  950.00 | 1500.00 | 1250.00 |
|  7499 |     30 | 1600.00 |  950.00 | 1600.00 | 1250.00 |
|  7698 |     30 | 2850.00 |  950.00 | 2850.00 | 1250.00 |
+-------+--------+---------+---------+---------+---------+
14 rows in set (0.00 sec)mysql>
mysql>
mysql> -- rows between unbounded preceding and unbounded following 从第一行到最后一行
mysql>  select a.empno,a.deptno,a.sal,->        first_value(a.sal)  over w as 'first',->        last_value(a.sal) over w as 'last',->        nth_value(a.sal,2) over w as 'top_2'->   from emp a->  window w  as (partition by a.deptno order by sal rows between unbounded preceding and unbounded following)-> ;
+-------+--------+---------+---------+---------+---------+
| empno | deptno | sal     | first   | last    | top_2   |
+-------+--------+---------+---------+---------+---------+
|  7934 |     10 | 1300.00 | 1300.00 | 5000.00 | 2450.00 |
|  7782 |     10 | 2450.00 | 1300.00 | 5000.00 | 2450.00 |
|  7839 |     10 | 5000.00 | 1300.00 | 5000.00 | 2450.00 |
|  7369 |     20 |  800.00 |  800.00 | 3000.00 | 1100.00 |
|  7876 |     20 | 1100.00 |  800.00 | 3000.00 | 1100.00 |
|  7566 |     20 | 2975.00 |  800.00 | 3000.00 | 1100.00 |
|  7788 |     20 | 3000.00 |  800.00 | 3000.00 | 1100.00 |
|  7902 |     20 | 3000.00 |  800.00 | 3000.00 | 1100.00 |
|  7900 |     30 |  950.00 |  950.00 | 2850.00 | 1250.00 |
|  7521 |     30 | 1250.00 |  950.00 | 2850.00 | 1250.00 |
|  7654 |     30 | 1250.00 |  950.00 | 2850.00 | 1250.00 |
|  7844 |     30 | 1500.00 |  950.00 | 2850.00 | 1250.00 |
|  7499 |     30 | 1600.00 |  950.00 | 2850.00 | 1250.00 |
|  7698 |     30 | 2850.00 |  950.00 | 2850.00 | 1250.00 |
+-------+--------+---------+---------+---------+---------+
14 rows in set (0.00 sec)mysql>
mysql>  -- 1 preceding and 1 following   当前行的前一行到当前行的后一行
mysql>   select a.empno,a.deptno,a.sal,->        first_value(a.sal)  over w as 'first',->        last_value(a.sal) over w as 'last',->        nth_value(a.sal,2) over w as 'top_2'->   from emp a->  window w  as (partition by a.deptno order by sal rows between 1 preceding and 1 following)-> ;
+-------+--------+---------+---------+---------+---------+
| empno | deptno | sal     | first   | last    | top_2   |
+-------+--------+---------+---------+---------+---------+
|  7934 |     10 | 1300.00 | 1300.00 | 2450.00 | 2450.00 |
|  7782 |     10 | 2450.00 | 1300.00 | 5000.00 | 2450.00 |
|  7839 |     10 | 5000.00 | 2450.00 | 5000.00 | 5000.00 |
|  7369 |     20 |  800.00 |  800.00 | 1100.00 | 1100.00 |
|  7876 |     20 | 1100.00 |  800.00 | 2975.00 | 1100.00 |
|  7566 |     20 | 2975.00 | 1100.00 | 3000.00 | 2975.00 |
|  7788 |     20 | 3000.00 | 2975.00 | 3000.00 | 3000.00 |
|  7902 |     20 | 3000.00 | 3000.00 | 3000.00 | 3000.00 |
|  7900 |     30 |  950.00 |  950.00 | 1250.00 | 1250.00 |
|  7521 |     30 | 1250.00 |  950.00 | 1250.00 | 1250.00 |
|  7654 |     30 | 1250.00 | 1250.00 | 1500.00 | 1250.00 |
|  7844 |     30 | 1500.00 | 1250.00 | 1600.00 | 1500.00 |
|  7499 |     30 | 1600.00 | 1500.00 | 2850.00 | 1600.00 |
|  7698 |     30 | 2850.00 | 1600.00 | 2850.00 | 2850.00 |
+-------+--------+---------+---------+---------+---------+
14 rows in set (0.00 sec)

percent_rank、CUME_DIST

percent_rank语法:

percent_rank() over w
window w as  ([partition-by-clause] [order-by-clause] )

CUME_DIST语法

cume_dist() over w
window w as  ([partition-by-clause] [order-by-clause] )

percent_rank:
– percent_rank函数以0到1之间的分数形式返回某个值在数据分区中的排名
– percent_rank的计算公式为(rank-1)/(n-1)

CUME_DIST:
–一个5行的组中,返回的累计分布值为0.2,0.4,0.6,0.8,1.0;
–注意对于重复行,计算时取重复行中的最后一行的位置。
 

SELECT a.empno,a.ename,a.deptno,a.sal,percent_rank() over w as 'num',cume_dist() over w as 'cume'FROM emp awindow w  as (PARTITION BY a.deptno ORDER BY a.sal DESC)
;
mysql> SELECT a.empno,->        a.ename,->        a.deptno,->        a.sal,->        percent_rank() over w as 'num',->        cume_dist() over w as 'cume'->   FROM emp a->   window w  as (PARTITION BY a.deptno ORDER BY a.sal DESC);
+-------+--------+--------+---------+------+---------------------+
| empno | ename  | deptno | sal     | num  | cume                |
+-------+--------+--------+---------+------+---------------------+
|  7839 | KING   |     10 | 5000.00 |    0 |  0.3333333333333333 |
|  7782 | CLARK  |     10 | 2450.00 |  0.5 |  0.6666666666666666 |
|  7934 | MILLER |     10 | 1300.00 |    1 |                   1 |
|  7788 | SCOTT  |     20 | 3000.00 |    0 |                 0.4 |
|  7902 | FORD   |     20 | 3000.00 |    0 |                 0.4 |
|  7566 | JONES  |     20 | 2975.00 |  0.5 |                 0.6 |
|  7876 | ADAMS  |     20 | 1100.00 | 0.75 |                 0.8 |
|  7369 | SMITH  |     20 |  800.00 |    1 |                   1 |
|  7698 | BLAKE  |     30 | 2850.00 |    0 | 0.16666666666666666 |
|  7499 | ALLEN  |     30 | 1600.00 |  0.2 |  0.3333333333333333 |
|  7844 | TURNER |     30 | 1500.00 |  0.4 |                 0.5 |
|  7521 | WARD   |     30 | 1250.00 |  0.6 |  0.8333333333333334 |
|  7654 | MARTIN |     30 | 1250.00 |  0.6 |  0.8333333333333334 |
|  7900 | JAMES  |     30 |  950.00 |    1 |                   1 |
+-------+--------+--------+---------+------+---------------------+
14 rows in set (0.00 sec)

ntile

Ntile语法:

Ntile(expr) OVER w
window w as   ([ query_partition_clause ] order_by_clause)

Ntile 把数据行分成N个桶。每个桶会有相同的行数,正负误差为1

将员工表emp按照工资分为2、3个桶

-- 分成2个桶
SELECT ENAME, SAL, NTILE(2) OVER w as 'n' FROM EMP
window w  as (ORDER BY SAL ASC)
;-- 分成3个桶
SELECT ENAME, SAL, NTILE(3) OVER w as 'n' FROM EMP
window w  as (ORDER BY SAL ASC)
;
mysql> -- 分成2个桶
mysql> SELECT ENAME, SAL, NTILE(2) OVER w as 'n' FROM EMP-> window w  as (ORDER BY SAL ASC)-> ;
+--------+---------+------+
| ENAME  | SAL     | n    |
+--------+---------+------+
| SMITH  |  800.00 |    1 |
| JAMES  |  950.00 |    1 |
| ADAMS  | 1100.00 |    1 |
| WARD   | 1250.00 |    1 |
| MARTIN | 1250.00 |    1 |
| MILLER | 1300.00 |    1 |
| TURNER | 1500.00 |    1 |
| ALLEN  | 1600.00 |    2 |
| CLARK  | 2450.00 |    2 |
| BLAKE  | 2850.00 |    2 |
| JONES  | 2975.00 |    2 |
| SCOTT  | 3000.00 |    2 |
| FORD   | 3000.00 |    2 |
| KING   | 5000.00 |    2 |
+--------+---------+------+
14 rows in set (0.00 sec)mysql>
mysql> -- 分成3个桶
mysql> SELECT ENAME, SAL, NTILE(3) OVER w as 'n' FROM EMP-> window w  as (ORDER BY SAL ASC)-> ;
+--------+---------+------+
| ENAME  | SAL     | n    |
+--------+---------+------+
| SMITH  |  800.00 |    1 |
| JAMES  |  950.00 |    1 |
| ADAMS  | 1100.00 |    1 |
| WARD   | 1250.00 |    1 |
| MARTIN | 1250.00 |    1 |
| MILLER | 1300.00 |    2 |
| TURNER | 1500.00 |    2 |
| ALLEN  | 1600.00 |    2 |
| CLARK  | 2450.00 |    2 |
| BLAKE  | 2850.00 |    2 |
| JONES  | 2975.00 |    3 |
| SCOTT  | 3000.00 |    3 |
| FORD   | 3000.00 |    3 |
| KING   | 5000.00 |    3 |
+--------+---------+------+
14 rows in set (0.00 sec)

相关文章:

MySQL入门篇-MySQL高级窗口函数简介

备注:测试数据库版本为MySQL 8.0 这个blog我们来聊聊MySQL高级窗口函数 窗口函数在复杂查询以及数据仓库中应用得比较频繁 与sql打交道比较多的技术人员都需要掌握 如需要scott用户下建表及录入数据语句&#xff0c;可参考:scott建表及录入数据sql脚本 分析函数有3个基本组成…...

什么是 API(应用程序接口)?

API&#xff08;应用程序接口&#xff09;是一种软件中介&#xff0c;它允许两个不相关的应用程序相互通信。它就像一座桥梁&#xff0c;从一个程序接收请求或消息&#xff0c;然后将其传递给另一个程序&#xff0c;翻译消息并根据 API 的程序设计执行协议。API 几乎存在于我们…...

如何在外网访问内网的 Nginx 服务?

计算机业内人士对Nginx 并不陌生&#xff0c;它是一款轻量级的 Web 服务器/反向代理服务器及电子邮件&#xff08;IMAP/POP3&#xff09;代理服务器&#xff0c;除了nginx外&#xff0c;类似的apache、tomcat、IIS这几种都是主流的中间件。 Nginx 是在 BSD-like 协议下发行的&…...

vue2中defineProperty和vue3中proxy区别

区别一&#xff1a;defineProperty 是对属性劫持&#xff0c;proxy 是对代理对象 下面我们针对一个对象使用不同的方式进行监听&#xff0c;看写法上有什么不同。 // 原始对象 const data {name: Jane,age: 21 }defineProperty defineProperty 只能劫持对象的某一个属性&…...

将bean注入Spring容器的五种方式

前言 我们在项目开发中都用到Spring&#xff0c;知道对象是交由Spring去管理。那么将一个对象加入到Spring容器中&#xff0c;有几种方法呢&#xff0c;我们来总结一下。 ComponentScan Component ComponentScan可以放在启动类上&#xff0c;指定要扫描的包路径&#xff1b;…...

C生万物 | 常量指针和指针常量的感性理解

文章目录&#x1f4da;引言✒常量指针&#x1f50d;介绍与分析&#x1f4f0;小结与记忆口诀✒指针常量&#x1f50d;介绍与分析&#x1f4f0;小结与记忆口诀&#x1f449;一份凉皮所引发的故事&#x1f448;总结与提炼&#x1f4da;引言 本文我们来说说大家很困惑的两个东西&am…...

python 打包工具 pyinstaller和Nuitka区别

1.1 使用需求 这次也是由于项目需要&#xff0c;要将python的代码转成exe的程序&#xff0c;在找了许久后&#xff0c;发现了2个都能对python项目打包的工具——pyintaller和nuitka。 这2个工具同时都能满足项目的需要&#xff1a; 隐藏源码。这里的pyinstaller是通过设置key来…...

Python解题 - CSDN周赛第28期

上一期周赛问哥因为在路上&#xff0c;无法参加&#xff0c;但还是抽空登上来看了一下题目。4道题都挺简单的&#xff0c;有点遗憾未能参加。不过即使参加了&#xff0c;手速也未必能挤进前十。 本期也是一样&#xff0c;感觉新增的题目都偏数学类&#xff0c;基本用不到所谓的…...

DNS记录类型有哪些,分别代表什么含义?

DNS解析将域名指向IP地址&#xff0c;是互联网中的一项重要服务。而由于业务场景不同&#xff0c;在设置DNS解析时&#xff0c;需要选择不同的记录类型。网站管理人员需要准确了解每一种DNS记录类型所代表的含义和用途&#xff0c;才能满足不同场景的解析需求。本文中科三方简单…...

ICLR 2022—你不应该错过的 10 篇论文(上)

CV - 计算机视觉 | ML - 机器学习 | RL - 强化学习 | NLP 自然语言处理 ICLR 2023已经放榜&#xff0c;但是今天我们先来回顾一下去年的ICLR 2022&#xff01; ICLR 2022将于2022年 4 月 25 日星期一至 4 月 29 日星期五在线举行&#xff08;连续第三年&#xff01;&#xf…...

HydroD 实用教程(三)环境数据

目 录一、前言二、Location三、Wind Profile四、Directions五、Water5.1 Wave Spectrums5.2 Current Profile5.3 Frequency Set5.4 Phase Set5.5 Wave Height5.6 Regular Wave Set六、参考文献一、前言 SESAM &#xff08;Super Element Structure Analysis Module&#xff09;…...

第四章 统计机器学习

机器学习&#xff1a;从数据中学习知识&#xff1b; 原始数据中提取特征&#xff1b;学习映射函数f&#xff1b;通过映射函数f将原始数据映射到语义空间&#xff0c;即寻找数据和任务目标之间的关系&#xff1b; 机器学习&#xff1a; 监督学习&#xff1a;数据有标签&#x…...

Redis第一讲

目录 一、Redis01 1.1 NoSql 1.1.1 NoSql介绍 1.1.2 NoSql起源 1.1.3 NoSql的使用 1.2 常见NoSql数据库介绍 1.3 Redis简介 1.3.1 Redis介绍 1.3.2 Redis数据结构的多样性 1.3.3 Redis应用场景 1.4 Redis安装、配置以及使用 1.4.1 Redis安装的两种方式 1.4.2 Redi…...

Java面试题-消息队列

消息队列 1. 消息队列的使用场景 六字箴言&#xff1a;削峰、异步、解耦 削峰&#xff1a;接口请求在某个时间段内会出现峰值&#xff0c;服务器在达到峰值的情况下会奔溃&#xff1b;通过消息队列将请求进行分流、限流&#xff0c;确保服务器在正常环境下处理请求。异步&am…...

基于离散时间频率增益传感器的P级至M级PMU模型的实现(Matlab代码实现)

&#x1f468;‍&#x1f393;个人主页&#xff1a;研学社的博客&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5;&#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密…...

9个相见恨晚的提升办公效率的网站!

推荐9个完全免费的神器网站&#xff0c;每一个都是功能强大&#xff0c;完全免费&#xff0c;良心好用&#xff0c;让你相见恨晚。 1&#xff1a;知犀思维导图 https://www.zhixi.com/ 知犀思维导图是一个完全免费的宝藏在线思维导图工具。它完全免费&#xff0c;界面简洁唯美…...

java的双亲委派模型-附源码分析

1、类加载器 1.1 类加载的概念 要了解双亲委派模型&#xff0c;首先我们需要知道java的类加载器。所谓类加载器就是通过一个类的全限定名来获取描述此类的二进制字节流&#xff0c;然后把这个字节流加载到虚拟机中&#xff0c;获取响应的java.lang.Class类的一个实例。我们把实…...

Docker 笔记

Docker docker pull redis&#xff1a;5.0 docker images [image:57DAAA3E-CC88-454B-B8AC-587E27C9CD3A-85324-0001A93C6707F2A4/93F703D2-5F44-49AB-83C7-05E2E22FB226.png] Docker有点类似于虚拟机 区别大概&#xff1a; docker&#xff1a;启动 Docker 相当于启动宿主操…...

用户认证-cookie和session

无状态&短链接 短链接的概念是指&#xff1a;将原本冗长的URL做一次“包装”&#xff0c;变成一个简洁可读的URL。 什么是短链接-> https://www.cnblogs.com/54chensongxia/p/11673522.html HTTP是一种无状态的协议 短链接&#xff1a;一次请求和一次响应之后&#…...

UUID的弊端以及雪花算法

目录 一、问题 为什么需要分布式全局唯一ID以及分布式ID的业务需求 ID生成规则部分硬性要求 ID号生成系统的可用性要求 二、一般通用方案 &#xff08;一&#xff09;UUID &#xff08;二&#xff09;数据库自增主键 &#xff08;三&#xff09;Redis生成全局id策略 三…...

synchronized 学习

学习源&#xff1a; https://www.bilibili.com/video/BV1aJ411V763?spm_id_from333.788.videopod.episodes&vd_source32e1c41a9370911ab06d12fbc36c4ebc 1.应用场景 不超卖&#xff0c;也要考虑性能问题&#xff08;场景&#xff09; 2.常见面试问题&#xff1a; sync出…...

RNN避坑指南:从数学推导到LSTM/GRU工业级部署实战流程

本文较长&#xff0c;建议点赞收藏&#xff0c;以免遗失。更多AI大模型应用开发学习视频及资料&#xff0c;尽在聚客AI学院。 本文全面剖析RNN核心原理&#xff0c;深入讲解梯度消失/爆炸问题&#xff0c;并通过LSTM/GRU结构实现解决方案&#xff0c;提供时间序列预测和文本生成…...

在web-view 加载的本地及远程HTML中调用uniapp的API及网页和vue页面是如何通讯的?

uni-app 中 Web-view 与 Vue 页面的通讯机制详解 一、Web-view 简介 Web-view 是 uni-app 提供的一个重要组件&#xff0c;用于在原生应用中加载 HTML 页面&#xff1a; 支持加载本地 HTML 文件支持加载远程 HTML 页面实现 Web 与原生的双向通讯可用于嵌入第三方网页或 H5 应…...

VM虚拟机网络配置(ubuntu24桥接模式):配置静态IP

编辑-虚拟网络编辑器-更改设置 选择桥接模式&#xff0c;然后找到相应的网卡&#xff08;可以查看自己本机的网络连接&#xff09; windows连接的网络点击查看属性 编辑虚拟机设置更改网络配置&#xff0c;选择刚才配置的桥接模式 静态ip设置&#xff1a; 我用的ubuntu24桌…...

uniapp手机号一键登录保姆级教程(包含前端和后端)

目录 前置条件创建uniapp项目并关联uniClound云空间开启一键登录模块并开通一键登录服务编写云函数并上传部署获取手机号流程(第一种) 前端直接调用云函数获取手机号&#xff08;第三种&#xff09;后台调用云函数获取手机号 错误码常见问题 前置条件 手机安装有sim卡手机开启…...

JavaScript 数据类型详解

JavaScript 数据类型详解 JavaScript 数据类型分为 原始类型&#xff08;Primitive&#xff09; 和 对象类型&#xff08;Object&#xff09; 两大类&#xff0c;共 8 种&#xff08;ES11&#xff09;&#xff1a; 一、原始类型&#xff08;7种&#xff09; 1. undefined 定…...

【p2p、分布式,区块链笔记 MESH】Bluetooth蓝牙通信 BLE Mesh协议的拓扑结构 定向转发机制

目录 节点的功能承载层&#xff08;GATT/Adv&#xff09;局限性&#xff1a; 拓扑关系定向转发机制定向转发意义 CG 节点的功能 节点的功能由节点支持的特性和功能决定。所有节点都能够发送和接收网格消息。节点还可以选择支持一个或多个附加功能&#xff0c;如 Configuration …...

基于鸿蒙(HarmonyOS5)的打车小程序

1. 开发环境准备 安装DevEco Studio (鸿蒙官方IDE)配置HarmonyOS SDK申请开发者账号和必要的API密钥 2. 项目结构设计 ├── entry │ ├── src │ │ ├── main │ │ │ ├── ets │ │ │ │ ├── pages │ │ │ │ │ ├── H…...

React从基础入门到高级实战:React 实战项目 - 项目五:微前端与模块化架构

React 实战项目&#xff1a;微前端与模块化架构 欢迎来到 React 开发教程专栏 的第 30 篇&#xff01;在前 29 篇文章中&#xff0c;我们从 React 的基础概念逐步深入到高级技巧&#xff0c;涵盖了组件设计、状态管理、路由配置、性能优化和企业级应用等核心内容。这一次&…...

深入理解 React 样式方案

React 的样式方案较多,在应用开发初期,开发者需要根据项目业务具体情况选择对应样式方案。React 样式方案主要有: 1. 内联样式 2. module css 3. css in js 4. tailwind css 这些方案中,均有各自的优势和缺点。 1. 方案优劣势 1. 内联样式: 简单直观,适合动态样式和…...