1

I have a table where storing details

ID     NAME
1       A
2       A
1       A

I need the output like

ID     Name   Count
1,2     A      3

Please help to get the output like that in oracle select query

4

1 Answer 1

2

In Oracle, you can use listagg(), but it has no distinct option. So, use a subquery and two levels of aggregation:

select listagg(id, ',') within group (order by id) as id, name, sum(cnt)
from (select id, name, count(*) as cnt
      from t
      group by id, name
     ) x
group by name;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the support

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.