gpt4 book ai didi

sql - 在 SQL Server 2008 中合并行

转载 作者:行者123 更新时间:2023-12-04 21:22:48 25 4
gpt4 key购买 nike

我有一张如下所示的表格:

Customer   |Type     |CountJoe        |Silver-S |1Joe        |Silver   |7Joe        |Gold     |3Joe        |Gold-S   |2

我需要合并它,使其看起来像下面这样:

Customer   |Type     |CountJoe        |Silver   |8Joe        |Gold     |5

帮助!

最佳答案

select Customer, [Type], SUM([Count]) from (
select Customer, replace([Type], '-S', '') [Type], [COUNT] from Customer
)
t
group by customer, [Type]

关于sql - 在 SQL Server 2008 中合并行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9349336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com