美文网首页SQL用法
sql分组字段的处理

sql分组字段的处理

作者: 成熟的青菜 | 来源:发表于2017-12-18 15:41 被阅读2次
TIM截图20171218153907new.png TIM截图20171218153729.png
 ---------------- sql语句 -----------
select * into #222
from (
select '张三' as name,'河北' as [address],'10:00' as arrive_time
union all 
select '张三' as name,'河北2' as [address],'12:00' as arrive_time
union all 
select '李四' as name,'江西1' as [address],'12:00' as arrive_time
union all 
select '李四' as name,'江西2' as [address],'12:00' as arrive_time
) as a

select * from #222 

select name, 
      stuff((select','+ convert(varchar(200),address) from #222
            where name=v.name for xml   path('')),1,1,'') as newaddress,       
      max(arrive_time) as maxtime       from #222 v         group by name
      

相关文章

网友评论

    本文标题:sql分组字段的处理

    本文链接:https://www.haomeiwen.com/subject/cqjmwxtx.html