Reputation: 58
I have a Sub query result Which is
Select string_Agg(amount) from(select amount from Audit_comp where auditreqid=id)
it returns 300,500,700
and i need some all these using
select sum(amount) from(select amount from Audit_comp where auditreqid=id)
it returns 1500 but my requirement is i need a below result in a single cell
300+500+700=1500
Please Suggest me
Upvotes: 1
Views: 36
Reputation: 1270191
Is this what you want?
Select (list_agg(amount, '+') within group (order by amount)) || '=' || sum(amount)
from Audit_comp
where auditreqid = id;
If your version of Oracle doesn't have list_agg()
, you can use your method:
Select replace(string_Agg(amount), ',', '+') || '=' || sum(amount)
from Audit_comp
where auditreqid = id
Upvotes: 1