How to get the values seperated by comma in a single column using SQL
问题 I have the below table and expected result. Please let me know if it is possible to achieve the result. Please refer the picture attached. 回答1: You can use listagg() : select e.id, e.name, e.sal, listagg(d.dept, ',') within group (order by d.dept_id) as depts, listagg(d.dept_id, ',') within group (order by d.dept_id) as dept_ids, from employee e left join department d on e.name = d.name group by e.id, e.name, e.sal; Some comments on the data model. Your department table should have a dept_id