DB ORACLE QUERY

可紊 提交于 2020-01-05 06:22:22

问题


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


回答1:


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;


来源:https://stackoverflow.com/questions/49276032/db-oracle-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!