解决方案 »
- 请教一个关于SQL子查询问题??求大神!!!
- mysql企业版怎么收费?社区版是否完全免费?
- 复制从主机positon 为什么是错误的
- 在数据中设置排序的序列号
- mysql存储过程批量插入数据
- MySQL中是否有类似MSSQL的链接服务器功能?如果没有,则应通过何种功能达到类似效果?
- mysql中相关量表的sql语句操作
- 怎么写一个触发器让后面ID跟着减1(在线等 急急急!!! 高手们帮帮忙!)
- MYSQL数据库转移的问题。#12 - Can't read dir of './discuz2_back/' (Errcode: 13)
- 求一个 mysql 查询分组与塞选 语句
- 求教~~各位~~~mysql错误~~
- MHA配置非root用户等效性问题
如果是从一个表中查找的话我能够找到,比如 把 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;两个表的我就捉急了。。
1,得到本周增加的分数
SELECT t2.id,u1.totalscore-t2.wscore
FROM `user` u1 INNER JOIN table1 t2 ON u1.playerid=t2.id
int i=1;
while(1){
if (tempid == t1.id) break;
i++;
}
这样效率非常低
所以能请教一下缺少什么必要的字段信息吗?
参考一下这个贴子的提问方式http://bbs.csdn.net/topics/320211382
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。
tempid 是什么字段,是什么业务涵义?
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的名次我不知到怎么弄
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;
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;