Excel中的排名
1、美式排名
函数=RANK(D5,$D 5 : 5: 5:D$11,0)
美式排名方法在实际运用当中用的最多。如图中所示,当出现两人分数相同,排名并列第2时,下一个名次直接为4。保证名次和总人数都保持为7。
2、中式排名
函数=SUMPRODUCT((D$5:D$11>D5)*(1/COUNTIF(D$5:D$11,D$5:D$11)))+1
中式排名如途中所示,在出现同样的相同分数,并列排名第2的时候,下一个排名为3,跟美式排名为第4不同,虽然人数总数为7,但它最终的排名为6。
SQL中的排名
-- 创建表
CREATE TABLE score (
id int(11) NOT NULL,
score float(5,2) DEFAULT NULL,
PRIMARY KEY (`id`));
-- 插入数据
INSERT INTO `score` VALUES ('1', '3.50');
INSERT INTO `score` VALUES ('2', '3.65');
INSERT INTO `score` VALUES ('3', '4.00');
INSERT INTO `score` VALUES ('4', '3.85');
INSERT INTO `score` VALUES ('5', '4.00');
INSERT INTO `score` VALUES ('6', '3.65');
1、美式排名
select
score,
(select count(distinct score) from score as s2 where s2.score >= s1.score) Rank
from score as s1
order by score DESC;
2、中式排名
select
scor