MYSQL 查询,对记录生成名次,并对名次进行针对性查询

下面语句大概意思是

1.某个活动,按最高分算出每个用户的得分名次,
2.从得分名次中,找出某个用户的具体名次


具体语句如下:

SELECT * FROM (
SELECT A.*,@rank:=@rank+1 AS pm FROM (SELECT `openid`,ROUND(MAX(`count`)) AS AvgS FROM hd_egg_detail GROUP BY openid  ORDER BY AvgS DESC) A ,(SELECT @rank:=0) B  
)v WHERE openid = 'ojCiAt1GwODTY0UcJaZQFaXORKVI'



你可能感兴趣的:(其他)