Shadow
Mysql实现排行榜sql语句
Mysql实现排行榜sql语句
直接上代码
-- 按余额查询排行榜
SELECT
m.id,
m.nickname,
m.openid,
m.avatar,
@rownum := @rownum + 1 AS rownum
FROM
( SELECT @rownum := 0 ) r,
( SELECT * FROM `tbl_member` WHERE credit> 0 ORDER BY credit DESC, created_at DESC ) AS m
-- 查询某个用户的余额 排行名词
SELECT
*
FROM
(
SELECT
m.id,
m.nickname,
m.openid,
m.avatar,
@rownum := @rownum + 1 AS rownum
FROM
( SELECT @rownum := 0 ) r,
( SELECT * FROM `tbl_member` WHERE credit> 0 ORDER BY credit DESC, created_at DESC ) AS m
) AS rankTable
WHERE
rankTable.openid = 'xxxxiilkjdlkj;flkj;lkkkks'
Dcr163的博客
http://dcr163.cn/648.html(转载时请注明本文出处及文章链接)