呼如林
2018-08-02 21:00:51
數(shù)據(jù)庫(kù)中有張表,表的定義為name, address,arrive_time,數(shù)據(jù)為張三,北京,10:00 ; 張三 ,河北,12:00 。怎么查詢顯示結(jié)果為 張三, 北京 河北, 12:00
2 回答

飲歌長(zhǎng)嘯
TA貢獻(xiàn)1951條經(jīng)驗(yàn) 獲得超3個(gè)贊
--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

絕地?zé)o雙
TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊
SELECT name, GROUP_CONCAT(DISTINCT address SEPARATOR ' ') AS address, max(arrive_time) AS arrive_time
FROM mytable
GROUP BY name
添加回答
舉報(bào)
0/150
提交
取消