Mat*_*thi 2 sql t-sql sql-server sql-server-2008
我有这样的表
OrderNo Item_Description1 Rate1 Quantity1 Item_Description2 Rate2 Quantity2 Item_Description3 Rate3 Quantity3
-------- ------------------ ------ ---------- ------------------ ------ ---------- ------------------ ------ ----------
1001 Laptop 50000 8 Air Conditioner 20000 10 Television 25000 12
1002 Washing Machine 35000 10 Camera 4000 20 Speaker 1500 15
Run Code Online (Sandbox Code Playgroud)
从这里我需要创建一个像这样的临时表或表:
OrderNo Item_Description Rate Quantity
-------- ------------------ ------ ----------
1001 Laptop 50000 8
Air Conditioner 20000 10
Television 25000 12
1002 Washing Machine 35000 10
Camera 4000 20
Speaker 1500 15
Run Code Online (Sandbox Code Playgroud)
有没有办法在SQL Server中执行此操作?
您还可以使用CROSS APPLY来取消数据的转移:
select t.order_no,
c.item_description,
c.rate,
c.quantity
from yourtable t
cross apply
(
select item_description1, rate1, quantity1 union all
select item_description2, rate2, quantity2 union all
select item_description3, rate3, quantity3
) c (item_description, rate, quantity)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4064 次 |
最近记录: |