当前位置:网站首页>Use of MySQL variables
Use of MySQL variables
2022-06-25 05:35:00 【Which floor do you rate moto】
Window functions can be viewed by clicking this link
- Error prone points of variable use
- about SET, have access to = or := As allocator
- Use SELECT Defining user variables can only use := As allocator ( Because in Africa SET In the sentence = Be treated as one ‘ Comparison operator ’.
- Through variables and if Statement to implement the window function (1):dense_rank()
SELECT
salary,
rk AS `RANK`
FROM
(
SELECT
salary,
IF
---- If @pres and salary equal , be @currank otherwise @currank be equal to @currank + 1
( @pres = salary, @currank, @currank := @currank + 1 ) AS rk,
@pres := salary
FROM
employee,(
SELECT
---- Declare variables @pres by -1,@currank by 0
@pres := - 1,
@currank := 0
) c1
ORDER BY salary DESC ) s
- Through variables and case when Statement to implement the window function (2):dense_rank()
SELECT
salary,
( CASE WHEN @pres = salary THEN @currank WHEN @pres := salary THEN @currank := @currank + 1 END ) AS `RANK`
FROM
employee,
( SELECT @pres := - 1, @currank := 0 ) AS c1
ORDER BY
salary DESC;
- adopt Count And DISTINCT Implement window functions (3):dense_rank()
SELECT
s.salary,
( SELECT COUNT( DISTINCT salary ) FROM employee e WHERE e.salary >= s.salary ) AS c1
FROM
employee s
ORDER BY
salary DESC;
- adopt group by,order by And variable implementation window function (4):dense_rank()
select
s.salary,
r.rank
from
employee s,
(
select
tmp1.salary,
(@rownum:[email protected]+1) as `Rank`
from
(select salary from employee group by salary order by salary desc) as tmp1,
(select @rownum:=0) tmp2
) as r
where
s.salary=r.salary
order by s.salary desc;
- adopt if Function to solve the following deformation problem

SELECT
DISTINCT s.Num
FROM
(
SELECT
t.*,
IF
( @before_num = t.Num, @times := @times + 1, 1 ) AS times,
@before_num := t.Num
FROM
( SELECT @before_num := NULL, @times := 1 ) r,
test t
) s
WHERE s.times >=3
边栏推荐
- JSON Library Tutorial from scratch (II): parsing digital learning and sorting notes
- 滲透測試-提權專題
- Design of IM login server and message server
- Vue uses keep alive to cache page optimization projects
- Deep analysis of epoll reactor code
- Eyeshot Ultimate 2022 Crack By Xacker
- Activereportsjs V3.0 comes on stage
- [Huawei machine test] hj16 shopping list
- XSS (cross site script attack) summary (II)
- Professional things use professional people
猜你喜欢
Learn the interface test, see it is very good, and make a note

Array: force deduction dichotomy
![[OSPF routing calculation (class I LSA router, class II LSA network, and class III LSA sum net)] -20211228-30](/img/c7/e38a7a5cd4c1e4105c3f3f246276c6.jpg)
[OSPF routing calculation (class I LSA router, class II LSA network, and class III LSA sum net)] -20211228-30

Example of dynamic programming 3 leetcode 55

Voxel based and second network learning

DOM document object model (I)

hr竟主动给这位测试小姐姐涨工资,她是怎么做到的?

Small sample learning data set

Attack and defense world web baby Web

C language - minesweeping
随机推荐
The article is on the list. Welcome to learn
Deeply understand the characteristics of standard flow and off standard elements
Page electronic clock (use js to dynamically obtain time display)
Characteristics of ES6 arrow function
Can bus extended frame
Example of dynamic programming 3 leetcode 55
Five simple data types of JS
Database overview
Dynamic programming example 2 leetcode62 unique paths
Keyboard key code value
Creation and use of MySQL index
ArcGIS Engine + Visual Studio installation tutorial
Electronic Society C language level 1 28, character diamond
Edge loss 解读
Detailed summary of position positioning
电子协会 C语言 1级 28 、字符菱形
TeeChart Pro ActiveX 2022.1
Go Methods and Interfaces
Makefile Foundation
Use of pytorch tensorboard