SQL根据第二张表字段值更新第一张表字段值

truncate table tab1

create table tab1
(
a int primary key not null identity(1,1),
b varchar(10),
c varchar(10),
d float,
e float,
f float
)
go

insert into tab1(b,c,d,e,f) values('a','aa',1,2,3);
insert into tab1(b,f) values('b','bb',3,4);
insert into tab1(b,f) values('c','cc',4,5);
insert into tab1(b,f) values('d','dd',5,6);
insert into tab1(b,f) values('e','ee',6,7);
go

select * from tab1;

--查询总分比平均分大的记录并按总分降序排列
select a,b,f,d+e+f as sumScore,(d+e+f)/3 as avgScore from tab1 where d+e+f>(d+e+f)/3 order by b,d+e+f desc;

--根据第二张表字段值更新第一张表字段值
--update 表一 set 表一.A = 表二.B from 表一,表二 where 表一.C = 表二.D
update tab1 set tab1.a=tab2.b from tab1,tab2 where tab1.c=tab2.d;

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...