首页 / MYSQL / MySQL 游戏排行榜
MySQL 游戏排行榜
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了MySQL 游戏排行榜,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1690字,纯文字阅读大概需要3分钟。
内容图文
![MySQL 游戏排行榜](/upload/InfoBanner/zyjiaocheng/450/3e54ce12838c418eb7379208126c2af2.jpg)
*************************** 1. row ***************************
Table: scores
Create Table: CREATE TABLE `scores` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`score` int(11) DEFAULT ‘0‘,
PRIMARY KEY (`id`),
KEY `k_s` (`score`)
) ENGINE=MyISAM AUTO_INCREMENT=1000001 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC 1 row in set (0.00 sec) mysql> select count(1) from scores;
+----------+
| count(1) |
+----------+
| 1000000 |
+----------+
1 row in set (0.00 sec) mysql> select id,score,(select count(1) from scores where score>= (select score
from scores where id = 100 order by score desc limit 1)) as rank from scores whe
re id = 100;
+-----+-------+--------+
| id | score | rank |
+-----+-------+--------+
| 100 | 64 | 370311 |
+-----+-------+--------+
1 row in set (1.05 sec) 2、分句完成。效率高。 存储过程: DELIMITER $$ DROP PROCEDURE IF EXISTS `test`.`sp_rank`$$ CREATE PROCEDURE `test`.`sp_rank`(IN str_id int(11))
BEGIN
-- user‘s score
DECLARE str_score int;
-- user‘s rank
DECLARE rank int;
select score from scores where id = str_id order by score desc limit 1 into str_score ;
select count(*) from scores where score >=str_score into rank;
-- output
select id,score,rank from scores where id = str_id;
END$$ DELIMITER ; mysql> call sp_rank(100);
+-----+-------+--------+
| id | score | rank |
+-----+-------+--------+
| 100 | 64 | 370311 |
+-----+-------+--------+
1 row in set (1.02 sec)
Query OK, 0 rows affected (1.02 sec)
MySQL 游戏排行榜
标签:
本文系统来源:http://www.cnblogs.com/jkred369/p/4581820.html
内容总结
以上是互联网集市为您收集整理的MySQL 游戏排行榜全部内容,希望文章能够帮你解决MySQL 游戏排行榜所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】