MySQL variables include system variables and system variables. The learning task this time is user-defined variables. User variables mainly include local variables and session variables. The declaration method of user-defined variables is as follows: @var_name, where the variable name consists of letters, numbers, ".", "_", and "$". Of course, you can include other characters when referring to a string or identifier (for example: @'my-var', @"my-var", or @my-var). User-defined variables are session-level variables. The scope of its variables is limited to the client link in which it is declared. When the client disconnects, all its session variables will be released. User-defined variables are not case-sensitive. Use the SET statement to declare user-defined variables: SET @my_var = 1; SET @my_var := 1; When not using set, use := assignment because using = may be considered as a comparison operator. The following is an example: Write a SQL query to implement score ranking. If two scores are the same, then the two score ranks should be the same. Note that the next rank number after a tie should be the next consecutive integer value. In other words, there should be no "holes" between the rows and columns. +—-+——-+ For example, given the Scores table above, your query should produce the following report (sorted by highest score): +——-+——+ Query statement: select Score, @rank := @rank + (@pre <> (@pre:=Score)) Rank from Scores ,(SELECT @rank := 0,@pre := -1) INIT ORDER BY Score DESC Note: @rank indicates the ranking of grades @pre indicates the score of the previous person When the score is different from the previous one, @rank = @rank + 1, otherwise, @rank = rank. Initialize @rank to 1 and @pre to -1. The experimental results are: The above detailed explanation of the use of custom parameters in MySQL is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Vue.js implements timeline function
>>: Analysis of Linux boot system methods
question: The following error occurred when insta...
This article example shares the specific code of ...
Table of contents Preface Introduction to QueryCa...
Ubuntu 20.04 has been released, bringing many new...
1. Install JDK 1. Uninstall the old version or th...
Table of contents 1. Problems encountered 2. Anal...
Table of contents 1. What is nginx? 2. What can n...
Process structure diagram Nginx is a multi-proces...
This article example shares the specific code for...
Preface In addition to the default built-in direc...
1. Apache server installation and configuration y...
1. Overview of DDL Atomicity Before 8.0, there wa...
background When developing a feature similar to c...
1. getBoundingClientRect() Analysis The getBoundi...
Nowadays, copying websites is very common on the I...