日期:2014-05-17 浏览次数:20934 次
select X,wm_concat(Y) from 你的表 group by X;
------解决方案--------------------
用wm_concat函数就能很容易满足你的要求,当然这个函数是10g之后才有的。你的oracle版本应该是10g之后的吧?
select x, wm_concat(y) from t group by x;
------解决方案--------------------
select X,wm_concat(Y) from 你的表 group by X;
------解决方案--------------------
with t(x, y, z) as ( select 1, 11, 'B' from dual union all select 1, 12, 'A' from dual union all select 1, 13, 'C' from dual union all select 2, 2, 'G' from dual union all select 3, 31, 'D' from dual union all select 3, 32, 'F' from dual union all select 4, 4, 'M' from dual ) select x, y from ( select x, wm_concat(y) over (partition by x order by z) y, row_number() over (partition by x order by z desc) rn from t) where rn = 1;
------解决方案--------------------
with t as ( select 1 as x, 11 as y, 'B' as z from dual union all select 1, 12, 'A' from dual union all select 1, 13, 'C' from dual union all select 2, 2, 'G' from dual union all select 3, 31, 'V' from dual union all select 3, 32, 'F' from dual union all select 4, 4, 'M' from dual ) select X,wm_concat(Y) from ( select * from t order by Z) group by X;