Mssql根据列值将行拆分为多行

问题描述 投票:0回答:1

我有一个关于根据列值拆分行的问题

我的示例数据集是:

id, ExpenseType, Price
1, Car, 100
2, Hotel, 50

我想将那些具有某些费用类型(例如Car)的行拆分为两行。其他应保留为一行。

First row Price *70 
Second Row Price *30 

返回的数据集应为

id, ExpenseType, Price
1, Car, 70 
1, Car, 30 
2, Hotel, 50

感谢您提前回答

sql sql-server
1个回答
1
投票

一种简单的方法使用union all

© www.soinside.com 2019 - 2024. All rights reserved.