我有一个名为 Dummy 的表,如下所示:
No. Name
1 ABC
2 NMD
2 SDSDS
1 23ererer
现在我想Name
用给定的数字连接所有列
例如。说不。1
我想ABC23ererer
作为我的输出吗
这将在 ORACLE(SQL) 中完成,而不使用 PL-SQL。
如何才能做到这一点?
这可能会有所帮助...
select NO,
listagg(NAME, ',') within group (order by NAME) as name
from TableName
group by NO
或者检查这个
oracle10g 不支持 LISTAGG。如果您有 10g,我认为以下查询将对您有所帮助。
select No, rtrim(Name,',') Name
from ( select No
, Name, rn
from yourtable
model
partition by (No)
dimension by (row_number() over
(partition by No order by Name) rn
)
measures (cast(Name as varchar2(40)) Name)
rules
( Name[any] order by rn desc = Name[cv()]||''||Name[cv()+1]
)
)
where rn = 1
order by NO
在 sql fiddle 中查看您的演示
SELECT "No.", LISTAGG(Name, ',') WITHIN GROUP (ORDER BY "No.") AS Name
FROM TableName
GROUP BY "No.";
尝试这个 :
选择号码+' '+ 名称 FROM table_name