Hospital Insurance PatientCount
H1 I1 1
H1 I1 2
H2 I1 1
H2 I2 1
表由保險公司爲希望將這個表,
Hospital Insurance PatientCount
H1,H2 I1 4
H2 I2 1
使用
select
stuff((select ', ' + Hospital
from Insurances
where (InsuranceName = i.InsuranceName)
for xml path(''),type).value('(./text())[1]','varchar(max)')
,1,2,'') as Hospitals,
i.InsuranceName,
sum(i.PatientsCount)
from Insurances i
group by i.InsuranceName;
輸出的嘗試:
Hospital Insurance PatientCount
H1,H1,H2 I1 4
H2 I2 1
你得到了什麼錯誤? – tharif
該查詢工作正常,期望我希望不同的醫院 –
在您的輸出之後發佈您期望的輸出 – tharif