当前位置:网站首页>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
边栏推荐
- [pan Wai 1] Huawei computer test
- Basic bit operation symbols of C language
- Unsupervised domain adaptation in semantic segmentation:a review unsupervised domain adaptation in semantic segmentation: a review
- The k-th node of the binary search tree [sword finger offer]
- Use of pytorch tensorboard
- Electronic Society C language level 1 28, character diamond
- Various pits encountered in the configuration of yolov3 on win10
- The construction and usage of wampserver framework
- Analysis of IM project framework
- 1.6.3 use tcpdump to observe DNS communication process
猜你喜欢

Visual studio 2022 interface beautification tutorial

Personalized Federated Learning with Moreau Envelopes

Common cluster deployment schemes in redis

Route parameters to jump to the page and transfer parameters -- > hidden parameter list

Baidu ueeditor set toolbar initial value

Detailed summary of float

渗透测试-提权专题

2021-03-23

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

CTFHub-rce
随机推荐
Even if you are not good at anything, you are growing a little bit [to your 2021 summary]
C language -- Sanzi chess
February 20ctf record
hr竟主动给这位测试小姐姐涨工资,她是怎么做到的?
Detailed summary of float
H5 canvas drawing circle drawing fillet [detailed explanation]
Design of IM login server and message server
TX Text Control 30.0 ActiveX
Go deep into the working principle of browser and JS engine (V8 engine as an example)
Go Methods and Interfaces
ERDAS 9.2 installation tutorial
Pointer array function combination in C language
Detailed summary of position positioning
What happens when you use "-fno exceptions", "new T"- With “-fno-exceptions”, what happens with “new T”?
UVA816 Abbott’s Revenge
Critical dependency: require function is used in a way in which dependencies
Matlab notes
渗透测试-提权专题
The construction and usage of wampserver framework
Understand JS high-order function and write a high-order function