Subject | Re: [firebird-support] help with a select, please! |
---|---|
Author | Sergio H. Gonzalez |
Post date | 2009-04-03T20:27:42Z |
> Assuming the first of your tables to be named CHARTS (OK, not the bestThanks Svein!!!
> name) containing a field to sum named MyField and the latter, linking
> table to be called ACCOUNTS, the following SQL should get you the sum
> for the group you desire:
>
> WITH RECURSIVE GROUPCONTAINS(SUBCODE, CODE)
> AS (SELECT A.CODE, A.SUMMARIZES_IN
> FROM ACCOUNTS A
> WHERE A.SUMMARIZES_IN = :CODE
> UNION ALL
> SELECT A.CODE, A.SUMMARIZES_IN
> FROM GROUPCONTAINS G
> JOIN ACCOUNTS A ON G.SUBCODE = A.SUMMARIZES_IN)
>
> SELECT SUM(C.MyField) FROM GROUPCONTAINS G
> JOIN CHARTS C ON G.SUBCODE = C.CODE
It does exactly what I need... the only problem is that I understand how it
works, in the same way I undestand the Big Bang!! :) mmhh... I'd love to read
some article about recursive sql with firebird... any chance you know where I
can find it? I've tried with the documentation of FB, but couldn't find any
tutor...
Thanks a millon!!!
-s