下面这样SQl语句怎么写?

cenny_1996 2008-11-17 06:36:59
如图:
表seven:
sid name sddress
1 hua kkk
2 guan ddd
3 hh lll
4 kkk yyy
~~~~~~~
表three:
tid name sdd
1 hua
3 hh
4 kkk
~~~~~~~~~~~~~~~~~~~~~`
怎么用sql语句把tid=sid的sddree值考到表three的字段sdd里?也就是three表最后的结果为:
表three:
tid name sdd
1 hua kkk
3 hh 111
4 kkk yyy



...全文
93 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
水族杰纶 2008-11-17
  • 打赏
  • 举报
回复
set nocount on
declare @seven table(sid int, name varchar(10), sddress varchar(10))
insert @seven select 1, 'hua' , 'kkk'
insert @seven select 2, 'guan', 'ddd'
insert @seven select 3, 'hh' ,'lll'
insert @seven select 4, 'kkk' , 'yyy'
declare @three table(tid int, name varchar(10) ,sdd varchar(10))
insert @three select 1 ,'hua',null
insert @three select 3 ,'hh' ,null
insert @three select 4 ,'kkk',null
update t set sdd=s.sddress from @seven s inner join @three t on s.sid=t.tid
select * from @three
/*tid name sdd
----------- ---------- ----------
1 hua kkk
3 hh lll
4 kkk yyy
*/
时光瞄 2008-11-17
  • 打赏
  • 举报
回复
update a set a.sdd=b.sddress from seven b join three a on b.tid=a.sid
等不到来世 2008-11-17
  • 打赏
  • 举报
回复

update three
set sdd=seven.sddress
from seven
where three.sid=seven.tid

34,575

社区成员

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

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