select (select sum(cost) from a where id=xxx) ys, (select sum(cost) from b where id=xxx) yf, ys-yf from abc
我这么写貌似是错的,必须再写一遍两个子查询用减号相连么?
1
petelin 2016-07-13 19:46:03 +08:00 via Android
可以考虑 join
|
2
delavior 2016-07-13 19:51:29 +08:00
必须再嵌套一层,定义的别名在同一个 select 里肯定是无效的
|
3
petelin 2016-07-13 19:53:59 +08:00
`select a.sum - a.sum from (select id,sum(in_money) as sum from A where id = 0) as a,(select id,sum(out_money) as sum from B where id = 0) as b;`
`select (select sum(in_money) from A where id = 0) - (select sum(out_money) from B where id = 0);` |