当前位置:网站首页>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
边栏推荐
- About the definition of pointer variables (personal notes)
- [OSPF routing calculation (class I LSA router, class II LSA network, and class III LSA sum net)] -20211228-30
- Database low-end SQL query statement fragment
- Mirror image of binary tree
- A review of small sample learning
- Analysis of IM project framework
- Go Methods and Interfaces
- Pytorch- daily learning notes of some small functions involving training
- JSON Library Tutorial from scratch (III): parsing strings, learning and sorting notes
- H5 native player [learn video]
猜你喜欢

DOM document object model (I)

Interface learning

Read the general components of antd source code

Deep learning non local neural networks

Design of IM login server and message server

Dynamic programming example 1 leetcode 322 coin change

Visual studio 2022 interface beautification tutorial

1.5.3 use tcpdump to observe ARP communication process

Penetration test - right raising topic

Unsupervised domain adaptation in semantic segmentation:a review unsupervised domain adaptation in semantic segmentation: a review
随机推荐
Code learning-cvpr2020 unsupervised domain adaptive semantic segmentation: intra advance
DOM document object model (I)
Uva1103 ancient pictograph recognition
February 19 CTF exercise
Personalized Federated Learning with Moreau Envelopes
1.5.3 use tcpdump to observe ARP communication process
Design of IM login server and message server
HR took the initiative to raise the salary of the test lady. How did she do it?
Route parameters to jump to the page and transfer parameters -- > hidden parameter list
Use serialize in egg to read and write split tables
渗透测试-提权专题
Characteristics of ES6 arrow function
Professional things use professional people
JS handwriting depth clone array and object
Jason learning
Everything is an object
Enhanced paste quill editor
1.6.3 use tcpdump to observe DNS communication process
Depth of binary tree
Word of the Day