how can we write a column values horizontal by using sql stmt;
ex:
select name from table_name;(actual output)
a
b
c
d
require output is
a b c d
Answers were Sorted based on User's Feedback
Answer / pankaj goyal
SQL wm_concat function
Question: I have a table test_test and I need to count the
distinct mark columns and them display all matching values
on one line:
Name Mark
------- ------
ABC 10
DEF 10
GHI 10
JKL 20
MNO 20
PQR 30
The result should be like this, with the count and the rows
groups onto the same line;
mark count names
---- ----- -----------
10 3 ABC,DEF,GHI
20 2 JKL,MNO
30 1 PQR
Answer: By Laurent Schneider: You could write your own
aggregate function or use WM_CONCAT:
select
mark,
count(*),
wm_concat(name)
from
test_test
group by
mark;
Here is another example of using wm_contcat:
select
deptno,
wm_concat(distinct ename)
from
emp
group by
deptno;
DEPTNO WM_CONCAT(DISTINCTENAME)
---------- ----------------------------------------
10 CLARK,KING,MILLER
20 ADAMS,FORD,JONES,SCOTT,SMITH
30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD
| Is This Answer Correct ? | 9 Yes | 3 No |
Answer / ajit
select Replace ( Wm_concat( a ), ',' ) Actout
from Tablename;
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ramaraju
select listagg(cust,' ') within group(order by cust) from t2;
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / prativa mishra
select xmlagg(xmlelement(g,column_name)).extract('//text()')
from table_name
| Is This Answer Correct ? | 0 Yes | 2 No |
What are the types of keys?
How to rename a column in the output of sql query?
What are the parts of a sql statement?
What are different categories of sql commands?
What are the sql versions?
How will you a activate/deactivate integrity constraints?
What are the disadvantages of not performing database normalization?
what is the difference between delete and truncate statement in sql? : Sql dba
What has stored procedures in sql and how we can use it?
What are the different types of sql commands?
What is database sql?
What is cursor explain with example?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)