Untitled

 avatar
unknown
plain_text
2 years ago
1.3 kB
4
Indexable
select tmp."clientCode", sum(tmp.amount) as amount , tmp."destinationAccountNumber"
from (
	select distinct cat."clientCode", cat.amount, cat."destinationAccountNumber", cat."transactionCode"
	from customer_account_transactions cat
	inner join products p_origen on (p_origen.code  = cat."sourceAccountType")
	inner join products p_destination on (p_destination.code  = cat."destinationAccountType")
	inner join (
		select vw."productCategoryId", vw."incrementAmount", vw."minTicket"
		from vw_part_form_by_raffle vw
		where "raffleId" = 53 
		and vw.additional = false
		group by vw."productCategoryId", vw."incrementAmount", vw."minTicket"
	) tmp_origen on (tmp_origen."productCategoryId" = p_origen."productCategoryId") 
	inner join (
		select vw."productCategoryId", vw."incrementAmount", vw."minTicket"
		from vw_part_form_by_raffle vw
		where "raffleId" = 53 
		and vw.additional = false
		group by vw."productCategoryId", vw."incrementAmount", vw."minTicket"
	) tmp_dest on (tmp_dest."productCategoryId" = p_destination."productCategoryId") 
	where cat."clientCode" = '12054425'
	-- and tmp_dest."minTicket" > tmp_origen."minTicket" -- Para omitar las transacciones propias sin importar las categorias
) tmp
group by tmp."clientCode", 
tmp."destinationAccountNumber"
Editor is loading...