修改数据库某列的值为其他两列的值

2024-11-07 04:36:12
推荐回答(2个)
回答1:

你是指用"pivot"吗?
网上的例子,希望可以帮到你:
create table test(id int,name varchar(20),quarter int,profile int)
insert into test values(1,'a',1,1000)
,(1,'a',2,2000)
,(1,'a',3,4000)
,(1,'a',4,5000)
,(2,'b',1,3000)
,(2,'b',2,3500)
,(2,'b',3,4200)
,(2,'b',4,5500)

select id,name,
[1] as "一季度",
[2] as "二季度",
[3] as "三季度",
[4] as "四季度"
from test
pivot
( sum(profile) for quarter in ([1],[2],[3],[4]) ) as pvt

回答2:

update table set 列1=列2+列3