表A 表B
看这里
http://sqlfiddle.com/#!2/f5620/3
这个执行的结果还是不对啊,并没有求和
你太调皮,后来编辑过帖子了
看这个
http://sqlfiddle.com/#!2/9847b/12
create temporary table Aselect 1 as uid, 1 as mid, 100 as cashunion select 2, 2, 105union select 3, 3, 98union select 4, 4, 55union select 5, 5, 60union select 6, 6, 70;create temporary table Bselect 1 as uid, 1 as mid, 101 as cash, 100 as numberunion select 2, 1, 100, 100union select 3, 2, 105, 200union select 4, 2, 105, 300union select 5, 3, 60, 300union select 6, 3, 98, 300;select uid,mid, cash, (select sum(number) from B where mid=A.mid and cash=A.cash) from A
这个就是我想要的
select a.*,if(t.number is null,0,t.number) as number from a left join
(select b.mid,b.cash,sum(b.number) as number from b group by mid,cash) as t
on t.mid=a.mid and t.cash=a.cash
select a.uid, a.mid, a.cash, sum(b.number) from testa as a left join testb as b on a.mid=b.mid and a.cash = b.cash group by a.mid, a.cash
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号