当前位置:网站首页>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
边栏推荐
- How to install the blue lake plug-in to support Photoshop CC 2017
- Detailed summary of flex layout
- SQL lab range explanation
- Create dynamic array
- Tanhaoqiang C language practice
- Extend the toolbar of quill editor
- Prototypical Networks for Few-shot Learning
- Can bus extended frame
- Page electronic clock (use js to dynamically obtain time display)
- Understand JS high-order function and write a high-order function
猜你喜欢

Ranorex Studio 10.1 Crack

The article is on the list. Welcome to learn

Semantic segmentation cvpr2020 unsupervised intra domain adaptation for semantic segmentation through self supervision
![[Huawei machine test] hj16 shopping list](/img/54/d28f5aea9350af7797ca7c069e564d.jpg)
[Huawei machine test] hj16 shopping list
![H5 canvas drawing circle drawing fillet [detailed explanation]](/img/6f/a33a323b6cd0918066e8b71a22d841.jpg)
H5 canvas drawing circle drawing fillet [detailed explanation]

Various pits encountered in the configuration of yolov3 on win10

Instant messaging project (I)

Flex flexible layout for mobile terminal page production

Read the general components of antd source code

Enhanced paste quill editor
随机推荐
Semantic segmentation cvpr2019-advance: advantageous enterprise minimization for domain adaptation in semantic segmentation
Monkey test of APP automation
H5 canvas drawing circle drawing fillet [detailed explanation]
Use serialize in egg to read and write split tables
BUUCTF(web:1-50)
Electric store stores data
Detailed summary of position positioning
Database low-end SQL query statement fragment
Array and simple function encapsulation cases
Word quickly makes multiple single-sided table labels, number plates, etc
Array introduction plus example 01
SQL lab range explanation
Install pytorch through pip to solve the problem that torch cannot be used in jupyter notebook (modulenotfoundererror:no module named 'Torch').
Two dimensional array and function call cases of C language
Deeply understand the characteristics of standard flow and off standard elements
Everything is an object
Handwritten promise all
Mobile number regular expression input box loses focus verification
Unsupervised domain adaptation in semantic segmentation:a review unsupervised domain adaptation in semantic segmentation: a review
Bind simulation, key points of interpreting bind handwritten code [details]