11g里面用listagg: select listagg(name,',') within (order by id) from table 10g里面用wm_concat:select wm_concat(name) from table wm_concat是undocument的listagg是11g document的
把一列数据拼接成一个字符串比较简单: declare @test varchar(500) set @test=''; select @test=@test+name+',' from person select @test 但是如果数据中有重复选项,想去掉重复的就比较绕弯了. ) set @test=''; select distinct @test=@test+name+',' from person select @test 加distinct是不行的,我在sql server 2008
Oracle 查询出来的数据取第一条 --------------------------------------------------------------------------- 转载自:http://www.itpub.net/thread-246442-1-1.html select * from (select * from <table> order by <key>) where rownum=1; select * from (select * from &l
-- 演示将多条记录数据组合成一条sql插入语句(for mysql) function getTpl0(tname) -- 获取表各个字段 local t = { tpl_pack = {"packId","itemId","`group`","num","rate","rateType"}, } for k, v in pairs(t) do if tname == k then r
with temp as( select 'China' nation ,'Guangzhou' city from dual union all select 'China' nation ,'Shanghai' city from dual union all select 'China' nation ,'Beijing' city from dual union all select 'USA' nation ,'New York' city from dual union all se
select t.col1,t.col2 ,wmsys.wm_concat(t.col3||' ') AS col3 , wmsys.wm_concat(t.col4||'') as col4,wmsys.wm_concat(t.col5||'') as col5,wmsys.wm_concat(t.col6||'') as col6 from tablename t GROUP BY t.col1,t.col2 ;