当前位置:Gxlcms > 数据库问题 > 数据库行转列、列转行、字段拼接

数据库行转列、列转行、字段拼接

时间:2021-07-01 10:21:17 帮助过:34人阅读

select prd_no_chg_y,

SUBSTRING(t.prd_no_chg_y, number ,CHARINDEX(‘;‘,t.prd_no_chg_y+‘;‘,number)-number) prd_no_chg

from tb t,master..spt_values s

where s.number >=1

and s.type = ‘P‘

and SUBSTRING(‘;‘+t.prd_no_chg_y,s.number,1) = ‘;‘

 

行转列

select * into #b from #a a
PIVOT
(
SUM(summinute) FOR
a.fday IN (b1,b2)
) AS T

拼接stuff写法

SELECT id, 
                      value = stuff
                          ((SELECT     ‘,‘ + value
                              FROM         tb AS t
                              WHERE     t .id = tb.id FOR xml path(‘‘)), 1, 1, ‘‘)
FROM         tb
GROUP BY id

数据库行转列、列转行、字段拼接

标签:col   rgb   master   fda   ring   ast   rgba   har   substring   

人气教程排行