table1
player_id mission_id
1 3
2 4
1 5
1 6table2
item_id item_num
1 11
2 11
3 11table3
item_id mission_id item_num
1 3 5
2 4 5
3 5 5
4 6 5有这么段sql语句
$sql="select a.item_num-b.item_num as num1
from table3 a inner join table2 b on b.item_id=a.item_id
where a.mission_id in(select mission_id from table1 where player_id=$user_id)";这样查出来的是错误结果 比预想结果要大好多
我怎么才能得到上述我想要的结果
player_id mission_id
1 3
2 4
1 5
1 6table2
item_id item_num
1 11
2 11
3 11table3
item_id mission_id item_num
1 3 5
2 4 5
3 5 5
4 6 5有这么段sql语句
$sql="select a.item_num-b.item_num as num1
from table3 a inner join table2 b on b.item_id=a.item_id
where a.mission_id in(select mission_id from table1 where player_id=$user_id)";这样查出来的是错误结果 比预想结果要大好多
我怎么才能得到上述我想要的结果
解决方案 »
- 请教一个初级问题,并发插入能提高插入速度吗?
- mysql 存储过程 into 赋值问题
- 像赶集网那样的区域分类信息网站的数据库应该怎么设计?
- 关于在单机上安装MYSQL多服务,无法启动第二个mysql服务的问题
- 如何进行多表查询
- information_schema里面根本不正确
- rpm版的mysql安装到哪去了?
- 我第一次在XP下用mysql,可是为什么winmysqladmin.exe新建不了数据库?
- 我想在sql中的所有表中查询哪些表存在co1这个字段怎么弄,
- mysql自动重启,大概半天时间就自动重启了
- 我的光标为什么不能向下移动
- mysql 联查相减 老鸟帮忙看看 要怎么才能得出结果
player_id mission_id
1 3
2 4
1 5
1 6 table2
item_id item_num
1 11
2 11
3 11 table3
item_id mission_id item_num
1 3 5
2 4 5
3 5 5
4 6 5
player_id mission_id
1 3
2 4
1 5
1 6 table2
item_id item_num
1 11
2 11
3 11 table3
item_id mission_id item_num
1 3 5
2 4 5
3 5 5
4 6 5
首先 table1中select mission_id from table1 where player_id=1 查处
mission_id
3
5
6 然后 在table3中查处 条件是mission_id和上表相同
item_id item_num
1 5
3 5
4 5 最后和table2中相减 条件是item_id和上表相同 num
6
from table2 left join (
select item_id
from table1,table3
where table1.mission_id=table3.mission_id
and table1.player_id=1) t on table2.item_id=t.item_id
where t.item_id is null
from table2 left join (
select item_id
from table1 inner join table3 on table1.mission_id=table3.mission_id
where table1.player_id=1) t on table2.item_id=t.item_id
where t.item_id is nullselect table2.item_id
from table2
where item_id not in (
select item_id
from table1 inner join table3 on table1.mission_id=table3.mission_id
where table1.player_id=1
)