数据库中有张表,表的定义为name, address,arrive_time,数据为张三,北京,10:00 ; 张三 ,河北,12:00 。怎么查询显示结果为 张三, 北京 河北, 12:00
2 回答
饮歌长啸
TA贡献1951条经验 获得超3个赞
--sql server的写法
SELECT name,
STUFF((SELECT','+ convert(VARCHAR(200),address) FROM [TableName] WHERE name=V.name FOR XML PATH('')),1,1,'') AS Newaddress,
MAX(arrive_time) AS Maxtime
FROM [TableName] V
GROUP BY name
绝地无双
TA贡献1946条经验 获得超4个赞
SELECT name, GROUP_CONCAT(DISTINCT address SEPARATOR ' ') AS address, max(arrive_time) AS arrive_time
FROM mytable
GROUP BY name
添加回答
举报
0/150
提交
取消