求一个UPDATE语句!!
现有两个表
表tt1
fid f1 f2 f3 f4
1 228 300046 49 null
2 229 300047 66 null
3 230 300048 30 null
表tt2
fid f1 fx fs ft
1 300046 33445566 QTZTDB 62
2 33445566 300046 QTZTDB 60
3 300047 33889900 QTZTDB 62
4 33556699 300046 QTZTDB 60
5 1234533 300047 QTZTDB 60
6 300047 44556688 QTTSDB 62
7 300046 55668833 QTZTDB 62
更在需要更新表tt1的列f4,更新成tt2中:tt2.f1=tt1.f1 tt2.fs='QTZTDB' tt2.ft=62的条数
update后,tt1表应是这样的
fid f1 f2 f3 f4
1 228 300046 49 2
2 229 300047 66 1
3 230 300048 30 0
请高手给条update语句,谢谢!
问题点数:20、回复次数:6Top
1 楼happyflystone(无枪的狙击手)回复于 2006-03-30 12:30:58 得分 2
update tt1
set f4 = (select count(*) from tt2 where f1=a.f1 and
fs='QTZTDB' and ft=62)
from tt1 aTop
2 楼wfliu()回复于 2006-03-30 12:33:37 得分 0
tt2中:tt2.f1=tt1.f1 ???
如何相等 ?Top
3 楼yuweiwei(YWW(杨思))回复于 2006-03-30 13:07:55 得分 15
楼主的意思应该是这样才对
update tt1
set f4 = (select count(*) from tt2 where tt2.f2=tt1.f1 and
tt2.fs='QTZTDB' and tt2.ft=62) from tt1
Top
4 楼tntzbzc(华裔大魔王—抗日要从娃娃抓起)回复于 2006-03-30 13:41:59 得分 3
楼上语法写错了
update tt1
set f4 = (select count(*) from tt2 where tt2.f2=tt1.f1 and
tt2.fs='QTZTDB' and tt2.ft=62)
或者
update a
set f4 = (select count(*) from tt2 where tt2.f2=tt1.f1 and
tt2.fs='QTZTDB' and tt2.ft=62) from tt1 aTop
5 楼tntzbzc(华裔大魔王—抗日要从娃娃抓起)回复于 2006-03-30 13:44:34 得分 0
晕,没写错
是我眼花了Top
6 楼allfuly(阿虎)回复于 2006-03-30 13:48:01 得分 0
yuweiwei(YWW(杨思)) 才是正解!谢谢!!!
happyflystone(没枪的狙击手) 的和我的思想一样,所以得到的总不是想要的结果,不过仍然谢谢你
结账!!Top




