SQL:根据第二张表字段值更新第一张表字段值(2008.4.11笔试)
truncate table tab1create table tab1(a int primary key not null identity(1,1),b varchar(10),c varchar(10),d float,e float,f float)goinsert into tab1(b,c,d,e,f) values('a','aa',1,2,3);insert into tab1(b,c,d,e,f) values('b','bb',2,3,4);insert into tab1(b,c,d,e,f) values('c','cc',3,4,5);insert into tab1(b,c,d,e,f) values('d','dd',4,5,6);insert into tab1(b,c,d,e,f) values('e','ee',5,6,7);goselect * from tab1;--查询总分比平均分大的记录并按总分降序排列select a,b,c,d,e,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 = 表二.Dupdate tab1 set tab1.a=tab2.b from tab1,tab2 where tab1.c=tab2.d;
页:
[1]