insert into tbl_B(ranking, playerId, name,logTime) select 0, id, name, NOW() from tbl_A order by total desc limit 0, 100; 每隔2小时执行一次这个动作,每次从A表中取出前100,然后插入到B表中,但是我想要ranking这个字段每次都从1开始递增,也就是将这100条数据进行1,2,3,4,5.的排名记录下来,不知如何操作,请大神赐教
set @rank := 0; insert into tbl_B(ranking, playerId, name,logTime) select @rank := @rank + 1, id, name, NOW() from tbl_A order by total desc limit 0, 100; 加个变量试试,没环境测试。
set @r:=0 和 set @r=0 有区别吗
这样可以实现,谢谢, 可是我想在java中调用它,该如何调用呢?
没用过 java,你就整句当成一个 sql 字符串调用试试。
http://blog.csdn.net/acmain_chm/article/details/4095531 MySQL中的ROWNUM的实现 MySQL 几乎模拟了 Oracle,SQL Server等商业数据库的大部分功能,函数。但很可惜,到目前的版本(5.1.33)为止,仍没有实现ROWNUM这个功能。 下面介绍几种具体的实现方法.建立实验环境如下mysql> create table tbl ( -> id int primary key, -> col int -> );Que...
insert into tbl_B(ranking, playerId, name,logTime) select @rank := @rank + 1, id, name, NOW() from tbl_A order by total desc limit 0, 100;
加个变量试试,没环境测试。
和
set @r=0
有区别吗
这样可以实现,谢谢, 可是我想在java中调用它,该如何调用呢?
MySQL中的ROWNUM的实现
MySQL 几乎模拟了 Oracle,SQL Server等商业数据库的大部分功能,函数。但很可惜,到目前的版本(5.1.33)为止,仍没有实现ROWNUM这个功能。 下面介绍几种具体的实现方法.建立实验环境如下mysql> create table tbl ( -> id int primary key, -> col int -> );Que...
可以把他变为存储过程来调用、
使用String sql = "{ call 你的存储过程名(参数) }";
然后根据你的DAO执行该sql就可以了、
支持?参数绑定、