select a.id,a.a,b.b,c.c,a.a+b.b+c.c as value ,(a.a+b.b+c.c) / d.d as aver
from
((
(select id,sum(a_value) as a from A表 group by id) a inner join
(select id,sum(b_value) as b from B表 group by id) b on a.id=b.id
) inner join
(select x_id,sum(c_value) as c from C表 group by id) c on a.id=c.x_id
) inner join
(select x_id,sum(quantity) as d from D表 group by id) d on a.id=d.x_id[align=center]==== 思想重于技巧 ====
[/align]
from
((
(select id,sum(a_value) as a from A表 group by id) a inner join
(select id,sum(b_value) as b from B表 group by id) b on a.id=b.id
) inner join
(select x_id,sum(c_value) as c from C表 group by id) c on a.id=c.x_id
) inner join
(select x_id,sum(quantity) as d from D表 group by id) d on a.id=d.x_id[align=center]==== 思想重于技巧 ====
[/align]
1 20
3 40
x_id (1,3),其它表 (1,2),怎么对应?
d.id
sum(a_value) as a,
sum(b_value) as b,
sum(c_value) as c,
sum(a_value+b_value+c_value) as value
sum(a_value+b_value+c_value)/quantity as aver
from d
join a on d.id=a.id
join b on d.id=b.id
join c on d.id=c.x_id
group by d.id
我用你的方法出现错误了啊