1. 程式人生 > >mysql sql語句查詢指定資料在查詢資料列表中排名第幾

mysql sql語句查詢指定資料在查詢資料列表中排名第幾

需求是這樣的,我們有個排名列表,需要查詢出當前條件下的指定人員的資訊是在排序後的第幾條。

兩種sql解決方案

SELECT a.* FROM 

(SELECT     *,     (@i :[email protected] + 1) AS No FROM     jira_issue_statistics     , (SELECT @i:=0) AS it WHERE     year = 2018 and mounth = 10  ORDER BY  count DESC) as a    WHERE a.reporter = 'jianglei_tmp'

方案2:

SELECT year,reporter,count,rowno FROM (         select * from          (                     select * from(                             SELECT  year, mounth, reporter, count,(@rowno:

[email protected]+1) as rowno  FROM jira_issue_statistics csss where year = 2018 and mounth = 10 ORDER BY count desc                     ) bcc,(select (@rowno:=0)) b ORDER BY count DESC

        ) tempst where tempst.year = 2018 and tempst.mounth = 10      ORDER BY count desc 

) c  WHERE   c.reporter='jianglei_tmp';