hola tengo un tema con este select, y no se estará soportado
es un select que anida 2 tablas en el mismo selec pero este no funciona al ejecutar el select funciona todo bien, pero al usarlo en un cursor, no reconoce la columna idresource
[42702] ERROR: column reference "idresource" is ambiguous
alguna sugerencia
open curs_for_items for
select grupo.ori, grupo.typeitem,grupo.description,sum(grupo.amount) amount, sum(grupo.amounttax) amounttax, max(grupo.idresource) as idresource
from (
SELECT
eve.typeitem,
eve.description,
eve.amount,
eve.amounttax,
eve.idresource as idresource,
'EVENT' ori
FROM event eve
WHERE idtransaction = numberTransaction
UNION ALL
select pr.typeitem, pr.typetax, pr.amount, pr.amounttax, pr.idresource, pr.ori
from (
SELECT
evt.typeitem,
evt.typetax,
evt.amount,
0 AS amounttax,
(SELECT idresource
FROM event
WHERE id = evt.idevent) as idresource,
'TAX' ori
FROM eventtax evt
WHERE idtransaction = numberTransaction
AND idevent IS NOT NULL
) pr
UNION ALL
SELECT
evnull.typeitem,
evnull.typetax,
evnull.amount,
0 AS amounttax,
(SELECT idresource
FROM event
WHERE id IN (SELECT a.idevent
FROM eventtax a
WHERE a.id = evnull.idtax)) as idresource,
'TAX' ori
FROM eventtax evnull
WHERE idtransaction = numberTransaction
AND idevent IS NULL
) grupo
group by grupo.ori, grupo.typeitem,grupo.description,grupo.idresource
order by grupo.idresource;