MySQL get row position in ORDER BY

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

With the following MySQL table:

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


        
9条回答
  •  遇见更好的自我
    2020-11-22 14:45

    I was going through the accepted answer and it seemed bit complicated so here is the simplified version of it.

    SELECT t,COUNT(*) AS position FROM t      
     WHERE name <= 'search string' ORDER BY name
    

提交回复
热议问题