Preface In fact, I have never encountered this kind of situation where the results are numbered during a query before. It was only when my colleague was planning to change jobs and asked about this situation during the interview that I thought of studying it. The following is an analysis of a single table query as an example: SQL: SELECT (@i:=@i+1) i,user_id,user_name FROM `dt_user_all_orders`, (SELECT @i:=0) as i WHERE user_name='qqqqqqqqqqq' LIMIT 0,10; result: If you need to group and then display the sequence number: SELECT drug_productor,@y:=@y+1 as num FROM( SELECT drug_productor FROM ts_drug a GROUP BY drug_productor) c,(SELECT @y:=0) d result: analyze: At the beginning, a variable i is defined, and each increment of it results in ➕1, Here we review the way MySQL defines user variables: select @ variable name There are two ways to assign values to user variables, one is to use the "=" sign directly, and the other is to use the ":=" sign. The difference is that when using the set command to assign values to user variables, both methods can be used; when using the select statement to assign values to user variables, only the ":=" method can be used, because in the select statement, the "=" sign is regarded as a comparison operator. Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM. You may also be interested in:
|
<<: js implements a simple shopping cart module
>>: How to monitor and delete timed out sessions in Tomcat
Table of contents 1. What is Pinia? 2. Pinia is e...
This article example shares the specific code of ...
This article introduces the sample code of advanc...
Method 1: Use table attributes: header-cell-class...
Preface Vue (pronounced /vjuː/, similar to view) ...
Table of contents 1. Event Flow 1. Concept 2. DOM...
Preface The so-called fuzzy query is to provide q...
1. Download the zip archive version from the offi...
Table of contents Some basic configuration About ...
Part of the code: Copy code The code is as follow...
Many times we want the server to run a script reg...
Data Sharing What kind of data needs to be writte...
There are two common ways to download files in da...
It is often necessary to run commands with sudo i...
1. Experimental Environment serial number project...