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
原文:http://www.cnblogs.com/Fooo/p/5128107.html