一道sql题,请求帮助

tsunamilx 2008-12-31 10:51:07
遇到个sql的题目,请帮忙做一下
两张表 t1(a,b),t2(a,c) 括号里表示字段
t1的b列有数据,t2的c列没有数据
现在要根据 t1.a=t2.a 为t2.c加入对应的t1.b数据

不知道我是不是把题目说明白了-_-
总之请大家知道的帮我分析一下吧
谢谢~~
...全文
150 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
tsunamilx 2009-01-10
  • 打赏
  • 举报
回复
真是抱歉 我不是用ms sql server的
我只是想用最通用的sql语句写这个问题,不依赖于任何数据库
我已经在另外一个板块得到解决了
谢谢各位
pengxuan 2009-01-05
  • 打赏
  • 举报
回复

update t2 set c=t1.b from t1 inner join t2 on t1.a=t2.a
han_xc0521 2009-01-05
  • 打赏
  • 举报
回复
和高度高
whiteyundd 2009-01-05
  • 打赏
  • 举报
回复
你的是sql server不?
wujumao 2009-01-02
  • 打赏
  • 举报
回复

updaet t2 set c=t1.b from t1,t2 where t1.a=t2.a
meothfs 2009-01-02
  • 打赏
  • 举报
回复
update t1,t2
set t2.c=t1.b
from t2
join t1 on t1.a=t2.a
Channie 2009-01-02
  • 打赏
  • 举报
回复
update t2
set c=tt1.b
from t2 tt2 inner join t1 tt1
where tt1.a=tt2.a
-晴天 2009-01-02
  • 打赏
  • 举报
回复
在查询分析器中运行.
-晴天 2009-01-02
  • 打赏
  • 举报
回复
update t2
set c=tt1.b
from t2 tt2 inner join t1 tt1
where tt1.a=tt2.a
tsunamilx 2009-01-02
  • 打赏
  • 举报
回复
都是这个代码
根本没人看我上面说的话
只顾着发代码上来

能告诉我你们都是在什么环境下执行这个代码的吗
我直行不了阿
argent10 2009-01-02
  • 打赏
  • 举报
回复
2楼的的FEOM 后面少了一个t2表吧
argent10 2009-01-02
  • 打赏
  • 举报
回复

UPDATE t2
SET t2.c=t1.b
FROM t1,t2
WHERE t1.a=t2.a
lqiang83 2009-01-02
  • 打赏
  • 举报
回复
up
tsunamilx 2009-01-01
  • 打赏
  • 举报
回复
好像不用了
我自己试出来了

update t1,t2
set t2.c=t1.b
where t1.a=t2.a

结果我看是对的
tsunamilx 2009-01-01
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 josy 的回复:]
引用 5 楼 tsunamilx 的回复:

谢谢
如果用一般的sql语句能写吗


这些就是一般的sql语句啊,你说的“一般的sql语句”是指?
[/Quote]

可能我见的少
我好像没见过 update table set col=... from ... where ... 的句子
而且我执行出来在from这里是报错的
tsunamilx 2009-01-01
  • 打赏
  • 举报
回复
我试过了,2楼和3楼都会报错的
4楼的代码我不知道怎么执行
我并不熟悉mysql语法
能用一般sql语句吗
谢谢
百年树人 2009-01-01
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 tsunamilx 的回复:]
谢谢
如果用一般的sql语句能写吗
[/Quote]

这些就是一般的sql语句啊,你说的“一般的sql语句”是指?
tsunamilx 2009-01-01
  • 打赏
  • 举报
回复
谢谢
如果用一般的sql语句能写吗
npkaida 2009-01-01
  • 打赏
  • 举报
回复

declare @t1 table([a] int,[b] int)
insert @t1
select 1,2 union all
select 2,5

declare @t2 table([a] int,[c] sql_variant)
insert @t2
select 1,null union all
select 2,null

update @t2
set c=t1.b
from @t1 t1, @t2 t2
where t2.a=t1.a

select * from @t2

/*
a c
1 2
2 5
*/
Riverwcj 2009-01-01
  • 打赏
  • 举报
回复
update c
set t2.c=t1.b
where t1.a=t2.a
加载更多回复(2)

34,590

社区成员

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

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