学生成绩排行
建立表语句
CREATE TABLE `student` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL,
`score` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;
查询全部
select * from student;
select A.*,(select count(distinct score) + 1 from student as B where B.score > A.score)rank from student as A order by rank asc
//排行 中count(distinct score)如果改为count(0)效果是另一种
distinct去掉后 改为
select A.*,(select count(0) + 1 from student as B where B.score > A.score)rank from student as A order by rank asc