且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL中带有Order By子句的排名函数

更新时间:2023-12-03 17:28:28

根据您提供的链接,其外观应如下所示:

According to the link you gave it should look like this:

SELECT    a.*,
( 
            CASE a.field1 
            WHEN @curType 
            THEN @curRow := @curRow + 1 
            ELSE @curRow := 1 AND @curType := a.field1 END
          ) + 1 AS rank
FROM      table_a a,
          (SELECT @curRow := 0, @curType := '') r
ORDER BY  a.field1, a.field2 desc;

根据您提供的链接中的示例,这里有2个小提琴,一个是oracle,一个是mySql.

Here are 2 fiddles, one for oracle and one for mySql based on the example from the link you gave:

  1. oracle
  2. Mysql
  1. oracle
  2. Mysql