解决方案 »

  1.   

    哪位大神帮帮忙呀,头疼
    如果是从一个表中查找的话我能够找到,比如 把 totalscore 放到 table1 中,可以用select rowno from (select id,totalscore-wscore chazhi,(@rowno:=@rowno+1) as rowno from table1,(select (@rowno:=0)) b order by chazhi desc,id) c where id=1032;两个表的我就捉急了。。
      

  2.   

    2表关联,就用join来操作,你提供的表字段信息远远不够来写你的需求。先写一个统计分数的小例子吧:
    1,得到本周增加的分数
    SELECT t2.id,u1.totalscore-t2.wscore 
    FROM `user` u1 INNER JOIN table1 t2 ON u1.playerid=t2.id
      

  3.   

    没用join,我用 SELECT t1.id,(ut.totalscore-a.wscore) cha FROM table1 t1,user ut where t1.id=ut.playerid order by cha desc,id limit 10;也是可用找到统计的分数的排名呀不过我不知到怎么找某个id的排名名次。虽然可以用 SELECT t1.id,(ut.totalscore-a.wscore) cha FROM table1 t1,user ut where t1.id=ut.playerid order by cha desc,id 找到所有的本周有赢分记录的人,然后 对比所有玩家中哪行数据的t1.id等于需要的tempid
     int i=1; 
     while(1){
        if (tempid == t1.id) break;
       i++;
    }
    这样效率非常低
      
    所以能请教一下缺少什么必要的字段信息吗?
      

  4.   

    但是这样很多业务操作需要修改了,user表比较重要,操作较多的
      

  5.   

       建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
       参考一下这个贴子的提问方式http://bbs.csdn.net/topics/320211382
       
       1. 你的 create table xxx .. 语句
       2. 你的 insert into xxx ... 语句
       3. 结果是什么样,(并给以简单的算法描述)
       4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。
      

  6.   


    tempid 是什么字段,是什么业务涵义?
      

  7.   


    tempid 是我需要查找名次的ID 。
    我说的笨方法是指:
     我通过全部玩家排名的结果集(SELECT t1.id,(ut.totalscore-a.wscore) cha FROM table1 t1,user ut where t1.id=ut.playerid order by cha desc,id 结果集)  逐行取得t1.id 判断t1.id是不是等于tempid,这样我查看到第n行的时候,i就等于n ,而tempid == t1.id的时候 ,那么i就是我想要查看的ID的排名。补充: 排名我能找到,虽然我不知到效率好不好,但是起码能够一个语句直接查到。  但是查看某个ID的名次我不知到怎么弄
      

  8.   

    终于好了,参考 http://blog.csdn.net/sugang_ximi/article/details/6703804 自己弄了好久才弄好虽然感觉好乱,语法可能不是很好 找到 ID为1030的周赢分排名名次
    select * from(select id,pm,(@rowno:=@rowno+1) as rowno from (select a.id,a.nickname,(tu.totalscore-a.wscore) pm from table1 t1,user tu where t1.id=tu.playerid order by pm desc,id) b,(select (@rowno:=0)) c ) d where id=1030;
      

  9.   

    打错了  应该是  
    select * from(select id,pm,(@rowno:=@rowno+1) as rowno from (select t1.id(tu.totalscore-t1.wscore) pm from table1 t1,user tu where t1.id=tu.playerid order by pm desc,id) b,(select (@rowno:=0)) c ) d where id=1030;