码迷,mamicode.com
首页 > 数据库 > 详细

MySql排名查询

时间:2014-08-21 01:34:43      阅读:624      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   数据   ar   div   log   on   

-- --------------------------------------------------------

--
-- 表的结构 `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

 

MySql排名查询,布布扣,bubuko.com

MySql排名查询

标签:style   blog   color   数据   ar   div   log   on   

原文地址:http://www.cnblogs.com/Athrun/p/3926035.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!