MySQL get row position in ORDER BY

前端 未结 9 1071
囚心锁ツ
囚心锁ツ 2020-11-22 13:57

With the following MySQL table:

+-----------------------------+
+ id INT UNSIGNED             +
+ name VARCHAR(100)           +
+----------------------------         


        
9条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 14:42

    This is the only way that I can think of:

    SELECT `id`,
           (SELECT COUNT(*) FROM `table` WHERE `name` <= 'Beta') AS `position`,
           `name`
    FROM `table`
    WHERE `name` = 'Beta'
    

提交回复
热议问题