第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

根據(jù)ID連接值

根據(jù)ID連接值

素胚勾勒不出你 2019-10-22 21:05:16
我有一個名為“結(jié)果”的表,數(shù)據(jù)如下:Response_ID    Label12147          It was not clear12458          Did not Undersstand12458          Was not resolved12458          Did not communicate12586          Spoke too fast12587          Too slow現(xiàn)在,我希望輸出每個ID顯示一行,并將Label中的值連接起來并用逗號分隔我的輸出應如下所示:Response_ID    Label12147          It was not clear12458          Did not Undersstand,Was not resolved,Did not communicate12586          Spoke too fast12587          Too Slow我怎樣才能做到這一點:
查看完整描述

3 回答

?
DIEA

TA貢獻1820條經(jīng)驗 獲得超2個贊

您不能確定在子查詢中沒有order by語句的情況下串聯(lián)的字符串的順序。該.value('.', 'varchar(max)')部分用于處理Label包含XML不友好字符(如)的情況&。


declare @T table(Response_ID int, Label varchar(50))

insert into @T values

(12147,          'It was not clear'),

(12458,          'Did not Undersstand'),

(12458,          'Was not resolved'),

(12458,          'Did not communicate'),

(12586,          'Spoke too fast'),

(12587,          'Too slow')


select T1.Response_ID,

       stuff((select ','+T2.Label

              from @T as T2

              where T1.Response_ID = T2.Response_ID

              for xml path(''), type).value('.', 'varchar(max)'), 1, 1, '') as Label

from @T as T1

group by T1.Response_ID


查看完整回答
反對 回復 2019-10-22
?
侃侃爾雅

TA貢獻1801條經(jīng)驗 獲得超16個贊

DECLARE @Results TABLE(Response_ID INT, Label VARCHAR(80));


INSERT @Results(Response_ID, Label)

SELECT 12147,'It was not clear'

UNION SELECT 12458,'Did not Undersstand'

UNION SELECT 12458,'Was not resolved'

UNION SELECT 12458,'Did not communicate'

UNION SELECT 12586,'Spoke too fast'

UNION SELECT 12587,'Too slow';


WITH x AS 

(

  SELECT Response_ID FROM @Results 

  GROUP BY Response_ID

)

SELECT x.Response_ID, Label = STUFF((SELECT ',' + Label

    FROM @Results WHERE Response_ID = x.Response_ID

    FOR XML PATH('')), 1, 1, '')

    FROM x;


查看完整回答
反對 回復 2019-10-22
  • 3 回答
  • 0 關注
  • 582 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號