Subject | Re: [firebird-support] question about joins |
---|---|
Author | Michael Weissenbacher |
Post date | 2007-02-27T16:24:27Z |
Hi,
select m.id, sum(s.sales)/3 salessum, sum(c.costs)/3 costssum
from maintable m
left join salestable s on s.id = m.id
left join coststable c on c.id = m.id
where m.id = 1
group by m.id
I can't think of a better way to do it with a single statement. I guess
the performance would be bad with many records.
Michael
> My original hope was that I would return the results (1, 25.00, 14.00)For this case it would be possible to use something like:
> but I instead get (1, 75.00, 28.00). The joins take place between all
> records including the costs/sales tables. Is there any way around this?
> For what I'm doing, I really cannot use any sub select statements, nor
> can I use two separate select statements. Is it possible to do this
> with just one?
select m.id, sum(s.sales)/3 salessum, sum(c.costs)/3 costssum
from maintable m
left join salestable s on s.id = m.id
left join coststable c on c.id = m.id
where m.id = 1
group by m.id
I can't think of a better way to do it with a single statement. I guess
the performance would be bad with many records.
Michael