Subject | Re: [firebird-support] How merge two queries |
---|---|
Author | E. D. Epperson Jr |
Post date | 2014-09-10T16:34:50Z |
You could do it with a union.
Your first select would be:
select
EXTRACT(YEAR FROM DT.DATA_DOCUMENTO) AS ANNO,
SUM(DC.IMPORTO) AS IMPONIBILE, 0 AS I POST A
And your second select would be
select
EXTRACT(YEAR FROM DT.DATA_DOCUMENTO) AS ANNO,
0 AS IMPONIBILE,
SUM(DC.IMPORTO) AS IMPOSTA
On Sep 10, 2014 11:59 AM, "Luigi Siciliano luigisic@... [firebird-support]" <firebird-support@yahoogroups.com> wrote:
Hallo,
I have two queries:
First (results: ANNO, IMPONIBILE):
select
EXTRACT(YEAR FROM DT.DATA_DOCUMENTO) AS ANNO,
SUM(DC.IMPORTO) AS IMPONIBILE
from
DOC_CORPO DC,
DOC_TESTA DT,
VOCI V
WHERE
DT.ID = DOC_TESTA_ID
AND DT.DOCUMENTO_ID <> 'PRO'
AND EXTRACT(YEAR FROM DT.DATA_DOCUMENTO) = 2013
AND DC.VOCE_ID = V.ID
AND V.CONTRIBUTI = 1
GROUP BY EXTRACT(YEAR FROM DT.DATA_DOCUMENTO)
Second (results: ANNO, IMPOSTA):
select
EXTRACT(YEAR FROM DT.DATA_DOCUMENTO) AS ANNO,
SUM(DC.IMPORTO) AS IMPOSTA
from
DOC_CORPO DC,
DOC_TESTA DT
WHERE
DT.ID = DOC_TESTA_ID
AND DT.DOCUMENTO_ID <> 'PRO'
AND EXTRACT(YEAR FROM DT.DATA_DOCUMENTO) = 2013
AND DC.VOCE_ID = 'ENPACL'
GROUP BY EXTRACT(YEAR FROM DT.DATA_DOCUMENTO)
There is a way to merge those two queries to obtain the same result in
one query that results: ANNO, IMPONIBILE, IMPOSTA?
Thanks.
--
Luigi Siciliano
--------------------------
------------------------------------
------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Visit http://www.firebirdsql.org and click the Documentation item
on the main (top) menu. Try FAQ and other links from the left-side menu there.
Also search the knowledgebases at http://www.ibphoenix.com/resources/documents/
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
------------------------------------
Yahoo Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/firebird-support/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/firebird-support/join
(Yahoo! ID required)
<*> To change settings via email:
firebird-support-digest@yahoogroups.com
firebird-support-fullfeatured@yahoogroups.com
<*> To unsubscribe from this group, send an email to:
firebird-support-unsubscribe@yahoogroups.com
<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/