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

sql语句备忘

时间:2014-09-19 13:44:35      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   ar   art   sp   log   on   

一:根据用户的得分查询其排名

答:先查出分数比当前用户高的有几个,在查出积分跟当前用户相等,时间早于这个用户的有几个,相加就是排名

set @i = 0;
SELECT *, (@i := @i + 1) AS ranking from user_score order by score desc, create_time asc;

 

二:MySQL执行查询,增加自定义列从1开始增长到最大记录数模拟自增ID

SET @mycnt = 0;
SELECT (@mycnt := @mycnt + 1) AS id, procode,proname FROM tb_product;

MySQL中的ROWNUM的实现 http://blog.csdn.net/acmain_chm/article/details/4095531

 

sql语句备忘

标签:des   style   blog   http   ar   art   sp   log   on   

原文地址:http://www.cnblogs.com/Alight/p/3981209.html

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