SQL中的行合并

时间:2019-05-28 17:01:17

标签: sql

如何在单行中合并重复记录。

enter image description here

2 个答案:

答案 0 :(得分:1)

您需要聚合:

select id, max(lname) as lname, max(fname) as fname, max(address) as address,
       max(zip) as zip, max(city) as city, max(state) as state, max(phone)
from table t
group by id;

答案 1 :(得分:1)

您可以使用聚合:

select id, max(lname) as lname, max(fname) as fname, max(address) as address,
       . . . 
from t
group by id;