Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have a table in which the values are

id      value
----------------
1         10
1         20
1         30
2         33
2         34

I want the output given below using sql:

id          value
-------------------
1             10
              20
              30
--------------------
2             33
              34
-------------------- 
share|improve this question

Query:

SELECT id, ListAgg(to_char(value), chr(10) || chr(13)) WITHIN GROUP (ORDER BY value) "Values" 
FROM t1 GROUP BY id;

Output:

ID Values   
-- ----------
 1 10         
   20          
   30          

 2 33         
   34          

Setup:

DROP TABLE T1;
CREATE TABLE t1 AS (SELECT 1 id, level * 10 value FROM dual CONNECT BY level <=3);
INSERT INTO t1 VALUES (2,33);
INSERT INTO t1 VALUES (2,34);
share|improve this answer
    
Note that listagg requires Oracle 11g. – StilesCrisis Sep 28 '15 at 20:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.