首页 > 代码库 > MySql排名查询
MySql排名查询
-- ------------------------------------------------------------ 表的结构 `score`--CREATE TABLE IF NOT EXISTS `score` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(32) NOT NULL DEFAULT ‘‘, `scores` int(11) NOT NULL DEFAULT ‘0‘, PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;---- 转存表中的数据 `score`--INSERT INTO `score` (`id`, `name`, `scores`) VALUES(1, ‘a‘, 97),(2, ‘b‘, 90),(3, ‘c‘, 98),(4, ‘d‘, 97),(5, ‘e‘, 66);select a.name, a.scores, (select count(id) from score where scores>=a.scores) as mc from score a limit 0, 10select * from (select a.name, a.scores, (select count(id) from score where scores>=a.scores) as mc from score a) b where b.mc<=10select * from(select (select count(id)+1 from score where scores>a.scores) as mc,a.name, a.scoresfrom scroe a) b where b.mc<=10 order by b.mc
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。