求一条UPDATE语句

cbcool 2004-06-24 11:50:18
条件:T1里按年份月份放着相同的结构,(每个月的RID结构相同)
目的:把T1中5月份的P1值更新到6月份中对应的P1中
我的思路:把5的值select出来看作表b,然后根据表B更新表T1中的P1值
update T1
set a.P1 = b.P1
from T1 a,(select RID,P1 from T1 where Year = 2004,Month = 5) b
where a.RID = b.RID
and a.Year = 2004
and a.Month = 6

但是出错,请问该怎么写?谢谢!不想写存储过程,只想一条SQL语句搞定:)
...全文
265 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
cbcool 2004-06-28
  • 打赏
  • 举报
回复
zjcxc(邹建)给50,pisces007(蝶鱼)给20,其它的分别给10,再后面的没了就不给了:)谢谢!
leeboyan 2004-06-24
  • 打赏
  • 举报
回复
管理-〉给分->输密码->确定
cbcool 2004-06-24
  • 打赏
  • 举报
回复
怎么结贴老是出错呀?
cbcool 2004-06-24
  • 打赏
  • 举报
回复
谢谢!
leeboyan 2004-06-24
  • 打赏
  • 举报
回复
update t1 set p1=(select p1 from t1 a join t2 b on a.RID = b.RID where b.Year = 2004 and b.Month = 6 and a.Year = 2004 and a.Month = 5)
pisces007 2004-06-24
  • 打赏
  • 举报
回复
update T1
set P1 = b.P1
from T1 a inner join (select RID,P1 from T1 where Year = 2004 and Month = 5) b
on a.RID = b.RID
where a.Year = 2004
and a.Month = 6
victorycyz 2004-06-24
  • 打赏
  • 举报
回复
update t1
set P1 = (select P1 from t1 where rid=a.rid and year=2004 and month=5)
from t1 a
where year=2004 and month=6
chludlf 2004-06-24
  • 打赏
  • 举报
回复
update a

set P1 = b.P1

from T1 a,(select RID,P1 from T1 where Year = 2004,Month = 5) b
where a.RID = b.RID
and a.Year = 2004
and a.Month = 6
pisces007 2004-06-24
  • 打赏
  • 举报
回复
update T1
set P1 = a.P1
from T1 a inner join (select RID,P1 from T1 where Year = 2004 and Month = 5) b
on a.RID = b.RID
where a.Year = 2004
and a.Month = 6
zjcxc 元老 2004-06-24
  • 打赏
  • 举报
回复
update t1 set p1=b.p1
from t1 a,(
select rid,p1 from t1 where [year]=2004 and [month]=5
)b
where a.RID = b.RID
and a.[Year] = 2004
and a.[Month] = 6
zjcxc 元老 2004-06-24
  • 打赏
  • 举报
回复
update T1
set P1 = b.P1
from T1 a,(select RID,P1 from T1 where Year = 2004 and Month = 5) b
where a.RID = b.RID
and a.Year = 2004
and a.Month = 6

zjcxc 元老 2004-06-24
  • 打赏
  • 举报
回复
帮助你结,你也要说明给分给那些人,给多少啊
cbcool 2004-06-24
  • 打赏
  • 举报
回复
真的结不了,我的密码是174615,哪位老兄帮我结了吧谢谢

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧