Al__H
Al__H

Reputation: 306

Need to combine one column's value from many rows into a single row

I'm try to create a report on Teradata security (DBC.ALLRIGHTS). When a user has more than one permission, I would like to group those into one row.

These rows:

Would be combined like this:

Upvotes: 0

Views: 35

Answers (1)

Andrew
Andrew

Reputation: 8693

You can use XMLAgg for this:

select
databasename,
tablename,
username,
TRIM(TRAILING ',' FROM (XMLAGG(TRIM(AccessRight)|| ',' ORDER BY AccessRight) 
 (VARCHAR(10000))))
from
dbc.allrights
group by 1,2,3

Upvotes: 2

Related Questions