求一个Sql
时间:2011-12-07
来源:互联网
A表
keyname alias
1 11
2 22
3 33
B表
name info
22 asdfa
1 aedf
3 adsf
2 dsdf
3 dasdf
11 dasdf
33 dsfsadf
我现在想做的操作是,通过sql实现:
将B表记录里,Name字段 是 alias的修改成对应的 keyname.
坐等高手解惑
作者: zhl71199713 发布时间: 2011-12-07
SQL code
update b set b.name = (select a.keyname from a where a.alias = b.name)
作者: palm_civet 发布时间: 2011-12-07
作者: zhl71199713 发布时间: 2011-12-07
--等大牛 update B set name = (select keyname from A,B where A.alias=B.name) where A.alias = B.name;
作者: hllfl 发布时间: 2011-12-07
update b set b.name = (select a.keyname from a where a.alias = b.name) where exist (select 1 from a where a.alias = b.name)
作者: hackthissite 发布时间: 2011-12-07
--4楼 exists update B set B.name = (select A.keyname from A where A.alias = B.name) where exists (select 1 from A where A.alias = B.name)
作者: hllfl 发布时间: 2011-12-07
update A1,B1 set B1.name = (select keyname from A1,B1 where A1.alias=B1.name) where A1.alias = B1.name; update B set B.name = (select A.keyname from A where A.alias = B.name) where exists (select 1 from A where A.alias = B.name) -- 创建数据表 create table A ( keyname varchar(10), alias varchar(10) ) --测试数据 insert into A select '1','11' union all select '2','22' union all select '3','33' select * from A -- 创建数据表 create table B ( name varchar(10), info varchar(10) ) --测试数据 insert into B select '22','sdf' union all select '1','sdfsdf' union all select '3','sdf' union all select '2','dg' union all select '3','dhrt' union all select '11','ree' union all select '33','sdfs' select * from B; --exists用的不熟 哎
作者: hllfl 发布时间: 2011-12-07
2 sdf
1 sdfsdf
3 sdf
2 dg
3 dhrt
1 ree
3 sdfs
作者: hllfl 发布时间: 2011-12-07
A表
keyname alias
1 11
2 22
3 33
B表
name info
22 asdfa
1 aedf
3 adsf
2 dsdf
3 dasdf
11 dasdf
33 dsfsadf
方法一:
update B as b1, (select a.keyname as aName,b.name as bName from A a,B b where a.alias=b.name) as b2 set b1.name=b2.aName where b1.name=b2.bName;
方法二:
update B as b1,A as a set b1.name=a.keyname where b1.name=a.alias
作者: xiaozhengdong 发布时间: 2011-12-07
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28