In the case of sufficient time, I will often go to the forum to see if others have posted a post. If I can answer, try to reply as much as possible. I will learn together and become talented. Questions are as follows:
Answer the following:
create table #test
(bm varchar (10),
xm varchar (10),
kqh varchar (10),
rq datetime)
go
insert into #test
values ('XX 办', 'Pj', 999, '2016-10-13 07:00:05 '),
(' XX Office ',' Pj ', 999,' 2016-10-13 07:02:09 '),
(' XX Office ',' Pj ', 999,' 2016-10 -13 07:08:55 '),
(' XX Office ',' Pj ', 999,' 2016-10-14 07:09:25 '),
(' XX Office ',' Pj ', 999,' 2016 -10-14 07:50:45 '),
(' XX Office ',' Pj ', 999,' 2016-10-14 07:55:51 ')
select bm, xm, kqh, convert (varchar (10) , rq, 121),
stuff (
(
select ',' + right (convert (varchar (16), rq, 121),5)
from #test a
where a.bm=b.bm and convert(varchar(10),a.rq,121)=convert(varchar(10),b.rq,121) for XML path('')
),1,1,''
)
from #test b
group by bm,xm,kqh,convert(varchar(10),rq,121)
drop table #test