Hello All,

Please provide me your suggestions for helping me in this below

I would like to add two union statements and deliver the results as one resultset.

The query is as follows

select SUM(ctx3.receipt_no) FROM
SELECT count(distinct(ctx1.receipt_no)) as receipt from ipadmin.counter_txn ctx1
where ctx1.receipt_no in
(select ctx.receipt_no from ipadmin.counter_txn ctx
where ctx.belongs_to_cs = 10649734147450093088460 and ctx.txn_type = 'PAY'
group by ctx.receipt_no having sum(ctx.collection_amt)<=0)

union all

select count(distinct(ctx2.receipt_no)) as receipt
from ipadmin.counter_Txn ctx2
where ctx2.txn_type = 'REF' and ctx2.belongs_to_cs = 10649734147450093088460
GROUP BY ctx2.receipt_no having sum(ctx2.collection_amt) <> 0.00
) ipadmin.counter_txn ctx3

where ipadmin------ >owner
counter_txn -------> table name

when i run the query i am getting the message that aggregation can not be performed on aggregate query.

Please need your guys help

Thanks in advance

sanil krishna