求一条update语句,马上给分 3 张三 数学 78 id b1 b2 a_id 1 数学选择 70 3 2 数学计算 15 3??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 create table tablea ([id] int,a1 varchar(10),a2 varchar(10),a3 int)insert into tablea([id],a1,a2) select 1,'zhang3','chinese'insert into tablea([id],a1,a2) select 2,'li4','math'insert into tablea([id],a1,a2) select 3,'zhang3','math'drop table tableacreate table tableb([id] int,b1 varchar(10),b2 int,a_id int)insert into tableb select 1,'math1',70,3insert into tableb select 2,'math2',15,3insert into tableb select 3,'math2',70,2insert into tableb select 4,'math1',6,2insert into tableb select 5,'chinese1',65,1insert into tableb select 6,'chinese2',20,1/*update*/update tablea set a3=(select sum(b2) from tableb where tablea.id=a_id)/*the result*/select * from tableaid a1 a2 a3 ----------- ---------- ---------- ----------- 1 zhang3 chinese 852 li4 math 763 zhang3 math 85 update a set a3=(select sum(b2) from b where b.a_id=a.id) 表A有问题,每一个学生不可能只有一科成绩.但如果id不代表学生的号,两个表的关联性就太差了 哦,对了,还有这个表的结构问题,呵呵,谢谢mylkzy(),这个数据是我临时写过来的,现用的那个太复杂我没有粘出来,只是为了说明这个意思的,献丑了,不好意思。同样感谢你。不过我结完分了,不好意思,只能口头谢谢了。 时间函数处理 索引的应用 连接查询问题 【高分】多个不定参数编写存储过程如何防注入 数据库设计文档【急】 service broker 设置激活除了问题,求救啊 两个数据表多列比较如何用SQL语句完成,急盼高手指点,不甚感激! 百万级数据更新问题 如果SQL 2000查询分析器中查询超时,请问如何修改超时设置 给100分求做一触发器,在线等呀.......快来救命呀~~~~~~ 如何获得作业上次执行的时间? 在SQL server的存贮过程的参数能不能用游标?
insert into tablea([id],a1,a2) select 1,'zhang3','chinese'
insert into tablea([id],a1,a2) select 2,'li4','math'
insert into tablea([id],a1,a2) select 3,'zhang3','math'
drop table tableacreate table tableb([id] int,b1 varchar(10),b2 int,a_id int)
insert into tableb select 1,'math1',70,3
insert into tableb select 2,'math2',15,3
insert into tableb select 3,'math2',70,2
insert into tableb select 4,'math1',6,2
insert into tableb select 5,'chinese1',65,1
insert into tableb select 6,'chinese2',20,1/*update*/
update tablea set a3=(select sum(b2) from tableb where tablea.id=a_id)/*the result*/
select * from tablea
id a1 a2 a3
----------- ---------- ---------- -----------
1 zhang3 chinese 85
2 li4 math 76
3 zhang3 math 85