Subject | Re: Firebird Inner Join And SubSelect |
---|---|
Author | martinthrelly |
Post date | 2006-12-15T22:14:09Z |
hello. i am using firebird 1.5. the reason that i did not opt to use
the GROUP BY clause is that my proper sql actually contains about 10
select statements and 5 other inner joins. i just cut it down for
this example. so it felt wrong to be grouping it by all 10 criteria
just to get one SUM column.
what is the best way for me to do this sql do you think?
--- In firebird-support@yahoogroups.com, Svein Erling Tysvaer
<svein.erling.tysvaer@...> wrote:
the GROUP BY clause is that my proper sql actually contains about 10
select statements and 5 other inner joins. i just cut it down for
this example. so it felt wrong to be grouping it by all 10 criteria
just to get one SUM column.
what is the best way for me to do this sql do you think?
--- In firebird-support@yahoogroups.com, Svein Erling Tysvaer
<svein.erling.tysvaer@...> wrote:
>your
> Assuming the combination vatcode, vatvalue and netvalue is unique,
> select can be simplified, making the derived table unneccessary:wont
>
> select
> v.vatcode,
> sum(d.netvalue) as disbs
> v.vatvalue,
> v.netvalue
> from vattransactions v
> join disbursements d on v.transno = d.transno
> where v.vatquarter = 20
> and v.inputoutput = 'O'
> group by
> v.vatcode, v.vatvalue, v.netvalue
> order by
> v.vatcode
>
> HTH,
> Set
>
> martinthrelly wrote:
> > hi i am trying to run the following sql within IBExpert but it
> > run saying "invalid token Select". i realise this may be asimple
> > error i am making but could somebody please point me out why icannot
> > join a summed amount like this. thanks.
> >
> > select
> > v.vatcode,
> > d.disbs,
> > v.vatvalue,
> > v.netvalue
> > from vattransactions v
> > inner join (
> > select
> > sum(netvalue) as disbs
> > from disbursements) d on v.transno = d.transno
> > where v.vatquarter = 20
> > and v.inputoutput = 'O'
> > order by
> > v.vatcode
>