Get the App
SLTechnology News&Howtos  ›  Database  › 

Mysql's sql ranking

Shulou Source: shulou.com Published: 2022-06-01 04:59:00 09月28日 Update

I always feel that the oracle analysis function is powerful, and I always feel that there are too many similar functions in mysql, but I found that the introduction of variables in sql into mysql makes sql very flexible. I have done a ranking these days.

When the scores of the three players are equal, they are all in the second place, and when the fourth and fifth places are equal, they are all 4.5.

Some code is listed below, by sorting and then assigning the variable to the value of the previous line, and then calculating, the introduction of sensory variables can achieve a lot of complex algorithms, if it is a single analysis function in oracle, it can basically be implemented.

It feels that as long as the mind is there, all languages are the same.

Click (here) to collapse or open

Set @ allrow:=0, @ lastrn1:=0,@newcnt:=0,@ykmycnt:=0, @ ykrownum=1, @ lastxxdm=null

Select

If (@ lastrn1= rn1,@newcnt, if (rn=rn1,@newcnt:=rn,@newcnt:= (rn+rn1) / 2)) + 0 xxpm

@ lastrn1:=rn1

If (@ ykbjnr=t.xxdm,@allrow,@allrow:=rn) xxrs

@ ykbjnr:=t.xxdm aaa

T. *

From (

Select

If (@ ykbjnr=t.xxdm,@ykmycnt: = @ ykmycnt + 1 rn) + 0 rn

If (@ lastxxdm=t.zpm,@ykrownum:=@ykrownum,@ykrownum:=@ykmycnt) + 0 rn1

@ ykbjnr:=t.xxdm aa, @ lastxxdm:=t.zpm bb, t.*

From tmp_cj t

Order by t.xxdm,t.zpm

) t order by t.xxdm.rn desc without explanation, feel for yourself.

Tags: Function variable sense analysis complex powerful one line code content single thinking score algorithm language Datong second name sorting interpretation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Huawei Shulou Technology Docker Linux