select of.code AS "Offer code"
                    , of.description AS "Offer description"
                    , count(DISTINCT wo.id) AS "Transaction count"
                    , to_char(sum(wo.amount_without_tax), '99999999990.00') AS "Amount without tax"
                    , to_char(sum(wo.amount_with_tax), '99999999990.00') AS "Amount with tax"  
                from  cat_offer_template of 
                    INNER JOIN billing_wallet_operation wo  on wo.offer_code = OF.code 
                where  (  wo.STATUS = 'OPEN'  or ( wo.STATUS = 'TREATED' 
                    and EXISTS ( select 1  from billing_rated_transaction rt  where wo.rated_transaction_id = rt.id and rt.STATUS = 'OPEN' )  )  )  
                and(  of.code ilike '%' || :SEARCH_CRITERION || '%'  or OF.description ilike '%' || :SEARCH_CRITERION || '%'  )  
                group by of.code, of.description 
                order by of.code