SQL行合併問題

2023-01-01 10:55:49 字數 849 閱讀 9829

1樓:匿名使用者

oracle 10 以及以上版本可用:

select id,wmsys.wm_concat(bom) time from table

group by id

oracle 9

select id,substr(max(sys_connect_by_path(bom,',')),2) ename from

(select id,bom,row_number()over(partition by id order by id ) rn from table)

start with rn=1

connect by rn-1=prior rn and id=prior id

group by id

order by id

2樓:

借助於 sys_conenct_by_path 函式 , oralce 9i 開始才有的。

select t1.id, ltrim(max(sys_connect_by_path(t1.bom, ',')), ',')

from (select t.id,

t.bom,

min(t.bom) over(partition by t.id) minbom,

row_number() over(order by id) + dense_rank() over(order by id) rn

from t_test2 t) t1

start with t1.bom = t1.minbom

connect by prior rn = rn - 1

group by t1.id;

SQL 2欄位合併,SQL資料整合鏈結合併?

用sql實現有點困難,建議使用儲存過程吧。sql 裡 怎麼把一列的值合併成乙個字串 1 建立測試表,create table test str concat id varchar2 20 value varchar2 20 2 插入測試資料。insert into test str concat v...

怎麼合併兩個sql語句的查詢結果

select id 1,name 李某某 union all select 2,王某某union all select 2,王某某這樣合併不會去重 不要all 內部會有個去重操作 但是有all時後效率比沒all 高 select id,name from table1union select id,...

求SQL問題答案,!!!!高分求SQL問題答案,懂得大師請幫幫忙

1,if exists select name from sysobjects where name num em and type p drop procedure num em gocreate procedure num em as 員工號 userid select count userid...