1. Background Generally, in a data warehouse environment, we can easily use the row_number function to group data according to a certain dimension to achieve the effect of sorting the data numbers in each group. As shown in the figure below, this is the effect diagram generated in the MySQL environment. The grouping here is based on lcid, and num is equivalent to the effect achieved by the row_number function: 2. Implementation process 1. Set mysql variables Set up two variables set @row_number:=0; --Generate row_number sequence number according to the judgment result of lcid_no set @lcid_no:= 0; --Used to obtain the lcid column data of each row, and then compare it with the lcid data of the previous row. If they are the same, it will increase by 1, otherwise it will be 1 2. Use case when SELECT @row_number:=CASE WHEN @lcid_no = s.lcid THEN @row_number + 1 ELSE 1 END AS num, @lcid_no:=s.lcid AS lcid, s.lcid FROM r_qcloud_approval_fh_d s,(select @orw_number:=0,@lcid_no:=0) t ORDER BY s.lcid; 3. Process analysis <br /> If there are multiple identical data 3. Usage scenarios In a relational database like MySQL, there is no row_number function. This is the end of this article about the implementation process of row_number in MySQL. For more relevant content about row_number in MySQL, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Learn Node.js from scratch
>>: In-depth explanation of nginx location priority
Swap memory mainly means that when the physical m...
Preface 1. Debounce: After a high-frequency event...
This article describes how to install and configu...
Table of contents Preface 1. Brief Analysis of th...
1. Color matching effect preview As shown in the ...
1. Introduction Nginx is a free, open source, hig...
At first I thought it was a speed issue, so I late...
This article will introduce how to use radial-gra...
Setting min-width and max-width properties in tab...
1. First, generate the public key and private key...
Data cleaning (ETL) Before running the core busin...
background I originally wanted to download a 6.7 ...
The development of Docker technology provides a m...
Table of contents 1. What is Ts 2. Basic Grammar ...
Table of contents 1. Unzip 2. Create a data folde...