這些國家,哪些天有比賽?
drop table #UEFO_Country
CREATE TABLE #UEFO_Country
(
name varchar(30)
,rundate int
)
insert into #UEFO_Country
values ('German',20180101)
,('Spain',20180102)
,('France',20180103)
,('France',20180105)
,('Italy',20180104)
,('Italy',20180106)
,('Italy',20180107)
select name from #UEFO_Country
declare @String varchar(8000)=''
select @String=@String +'.'+name from #UEFO_Country
select @String
select name,
(
SELECT cast(rundate AS NVARCHAR ) + '.'
from #UEFO_Country
where name=t0.name --把name一樣的加起來
FOR XML PATH('')
) as DateList
from #UEFO_Country t0
select DISTINCT name,
datelist=
(
SELECT cast(rundate AS NVARCHAR ) + '.'
from #UEFO_Country
where name=t0.name --把name一樣的加起來
FOR XML PATH('')
)
from #UEFO_Country t0
select name,datelist from
(
select name,
datelist=
(
SELECT cast(rundate AS NVARCHAR ) + '.' from #UEFO_Country
where name=t0.name --把name一樣的加起來
FOR XML PATH('')
)
from #UEFO_Country t0
) a
group by name,datelist
order by datelist
SELECT * FROM STRING_SPLIT('England,Spain,Japan', ',') --for SQL Server 2016
REF
https://dotblogs.com.tw/supershowwei/2016/01/26/145353
https://dotblogs.com.tw/stanley14/2017/03/27/string_split_merge