Get rid from one column duplicate values in two column select

前端 未结 3 619
隐瞒了意图╮
隐瞒了意图╮ 2020-12-21 21:50

So, I`ve got two columns t1.NAME and t2.ITEMS, for each neme there can be more than one item assigned to it, so I want to select it like:

| NAME | ITEMS |
           


        
3条回答
  •  臣服心动
    2020-12-21 22:24

    This kind of operation should be done in presentation layer.

    But if you insist you can use sth like:

    SqlFiddleDemo

    SELECT DISTINCT NAME,
          LISTAGG(Items,  chr(13)||chr(10)) WITHIN GROUP (ORDER BY 1) OVER (PARTITION BY Name) AS Items
    FROM tab
    

    change tab with subquery that produce output you get now.

    The clue is to concatenate for every name corresponding Items and adding new line character CHR(13) + CHR(10).

提交回复
热议问题