-- 在MySQL中实现Rank普通排名函数
SELECT company_no, company_name,b_score, @curRank := @curRank + 1 AS rank
FROM credit_score p, (
SELECT @curRank := 0
) q
ORDER BY b_score DESC;
-- 在MySQL中实现Rank普通并列排名函数
SELECT company_no, company_name,b_score,
CASE
WHEN @prevRank = b_score THEN @curRank
WHEN @prevRank := b_score THEN @curRank := @curRank + 1
END AS rank
FROM credit_score p,
(SELECT @curRank :=0, @prevRank := NULL) r
ORDER BY b_score DESC;
-- 在MySQL中实现Rank高级并列排名函数
SELECT company_no, company_name,b_score, rank FROM
(SELECT company_no, company_name,b_score,
@curRank := IF(@prevRank = b_score, @curRank, @incRank) AS rank,
@incRank := @incRank + 1,
@prevRank := b_score
FROM credit_score p, (
SELECT @curRank :=0, @prevRank := NULL, @incRank := 1
) r
ORDER BY b_score DESC) s