sql—如何在mssql中将多行合并为一行

1dkrff03  于 2021-06-24  发布在  Hive
关注(0)|答案(2)|浏览(554)

这是我的数据:

id段国家/地区产品状态月/年
83916512政府空2014 83916512德国空2014 83916512空carretera空2014 83916512空完成空2014 83916512空2014 6月83916512空2014
我要低于输出

有谁能帮我做到这一点吗

bxfogqkk

bxfogqkk1#

SELECT Id
    ,COALESCE(segment) AS segment
    ,COALESCE(country) AS country
    ,COALESCE(product) AS product
    ,COALESCE(STATUS) AS STATUS
    ,COALESCE(month) AS month
    ,COALESCE(year) AS year
FROM TABLE
gt0wga4j

gt0wga4j2#

您可以使用以下sql select

select
    id,
    MAX(segment) as segment,
    MAX(country) as country,
    MAX(product) as product,
    MAX(status) as status,
    MAX(month) as month,
    MAX(year) as year
from tbl
group by id

相关问题