MySQL SQL数据排名查询某条数据是总数据的第几条

查询所有数据排名

1
2
SELECT a.yhid,a.zjf,a.dqjf,(@rowno:=@rowno+1) as rowno
FROM jfxt_yhjfxx a,(select (@rowno:=0)) b ORDER BY a.zjf DESC

指定查询某条数据的排名

1
2
3
4
SELECT * FROM (
SELECT a.yhid,a.zjf,a.dqjf,(@rowno:=@rowno+1) as rowno
FROM jfxt_yhjfxx a,(select (@rowno:=0)) b ORDER BY a.zjf DESC) c
WHERE c.yhid='f531aded-bd09-4574-8826-4482bd918f91'
posted @ 2018-06-28 15:54  tracy11111  阅读(309)  评论(0)    收藏  举报