gpt4 book ai didi

sql-server-2005 - 使用 Sql 查询从行到列

转载 作者:行者123 更新时间:2023-12-01 12:46:08 25 4
gpt4 key购买 nike

嗨,我有一个表格,其中的列为

              Cost     Rate

Repair 12
Repair 223
Wear 1000
Wear 666
Fuel 500
Repair 600
Fuel 450
Wear 400

现在我想要这个数据

             Repair    Wear   Fuel
825 2066 950

使用Sql查询

提前致谢

最佳答案

select sum(case when cost = 'Repair' then rate else null end) as Repair
, sum(case when cost = 'Wear' then rate else null end) as Wear
, sum(case when cost = 'Fuel' then rate else null end) as Fuel
from CostRateTable

关于sql-server-2005 - 使用 Sql 查询从行到列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1047498/

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