日期:2014-05-17  浏览次数:20693 次

一个查询的问题 合并两行记录。详情入内
有这么一句sql
select 'ID' as ids,'CODE' AS co,'' m1 from dual
Union all
select 'ID' as ids ,'' as co ,'NAME' m1 from dual


产生的结果
  ids co m1
1 ID CODE “此列空”
2 ID “此列空”NAME


注意此列空就是空的那种情况,csdn那个发出来自动就吧空格去掉 汗死
我想合并成
ID CODE NAME
这样一条数据 接下去要怎么写?????

------解决方案--------------------
SQL code
with
tb as(select 'ID' as ids,'CODE' AS co,'' m1 from dual
Union all
select 'ID' as ids ,'' as co ,'NAME' m1 from dual)
select ids ,
wm_concat(co) co,
wm_concat(m1) m1
from tb 
group by ids

------解决方案--------------------
SELECT MAX(ids) as ids,max(co) as co,max(m1) as m1 FROM 
(
select 'ID' as ids,'CODE' AS co,'' m1 from dual
Union all
SELECT 'ID' AS ids ,'' AS co ,'NAME' m1 FROM dual
);
------解决方案--------------------
With tb_data As
 (Select 'ID' As ids, 'CODE' As co, '' m1
From dual
Union All
Select 'ID' As ids, '' As co, 'NAME' m1 From dual)
Select ids, Max(co) co, Max(m1) m1 From tb_data Group By ids;