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, 10 select * from ( select a.name, a.scores, (select count(id) from score where scores>=a.scores) as mc from score a ) b where b.mc<=10 select * from (select (select count(id)+1 from score where scores>a.scores) as mc,a.name, a.scores from scroe a) b where b.mc<=10 order by b.mc
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。