怎样查询得到(100分)

D

dohye

Unregistered / Unconfirmed
GUEST, unregistred user!
表A有字段ID和RecQuantity
数据
001 200
001 100
表B有字段ID和SaleQuantity
数据
001 200
001 300
001 200
002 300
怎样查询得到
id totalRec totalsale
001 300 700
002 300

 
分两次查比较好查:
select sum(RecQuantity) from a where id=:para1
select sum(SaleQuantity) from a where id=:para2


 
分两次查确实容易
但不知怎样在同一个DBGrid里显示
 
不小心吧提问放到了
"非技术问题" 中
现转到文件型数据库中
 
select b.id as id,
sum(a.RecQuantity) as totalRec,
sum(b.SaleQuantity) as totalSale
from a, b where b.id=a.id group by id
 
我一用了 Another_eyes 的方法
但是这是叉乘连接,算出来的数量
要比实际数量多好几倍.
 
select a.id as id, sum(a.RecQuantity) as totalRec,
sum(b.SalQuantity) as totalsale
from a union join b group by id
 
多人接受答案了。
 
顶部