select id,keyword ,max(Confidence) as confidence, TimeRange=stuff((select ','+rtrim(begintime)+'-'+rtrim(endtime) from tb where id=a.id and keyword=a,keyword for xml path('')),1,1,'') from tb a group by id,keyword