我有3张桌子,想像下面给出的那样获取桌子
table bonus table dealer accountdetail
----------- ------------- ----------------
id type commission id by whom commission id account number
--- ----- ---------- ---- ------- ----------- ---- -----------
1 book 100 1 john 50 1 5423456789
2 pen 15 3 rana 20 2 4563778599
3 5679087765
代码是:
(select b.id,
b.commission,
ac.account
from bonus b,
accountdetail ac
where ac.id = b.id
order by ac.id)
union all
(select d.id,
d.commission,
ac.account
from dealer d,
accountdetail ac
where ac.id = d.id
order by ac.id)
输出为:
id commission account number --- ---------- ----------- 1 100 5423456789 1 50 5423456789 2 15 4563778599 3 20 5679087765
但是我想像这样
id commission account number
--- ---------- -----------
1 150 5423456789
2 15 4563778599
3 20 5679087765
请建议我如何结合记录并通过计算一次显示数据
预先感谢