Untitled
unknown
plain_text
a year ago
1.1 kB
3
Indexable
Never
select * from ( select ra.id, tp2.id, ae."raffleId", ae."ticketProcessId", ae."clientCode", COALESCE( rtrim(cli.name || ' ' || cli.surname), rtrim(ae."clientName" || ' ' || ae."clientLastName") ) as "fullName", count(distinct ae.reason) "cantidad de razones" from audit_excluded ae left join ticket_process tp on tp.status = 'completed' inner join raffle ra on ra.id = ae."raffleId" and ra."deletedAt" is null inner join ticket_process tp2 on tp2."raffleId" = ra.id and tp2.status = 'completed' left join hist_clients cli on cli."clientCode" = ae."clientCode" and ra."id" = ae."raffleId" and cli."ticketProcessId" = tp2."id" where ra.id = 47 and ( tp.id = ae."ticketProcessId" or ae."ticketProcessId" = 0 ) and ae."clientCode" in (coalesce(nullif(null, ''), ae."clientCode")) group by ra.id, tp2.id, ae."raffleId", ae."ticketProcessId", ae."clientCode", "fullName" ) q