请问一个SQL 查询语句

来源:百度知道 编辑:UC知道 时间:2024/07/06 15:22:46
tab1 tab2
1 a c a a1
2 b a b b1
3 c b c c1
4 a c

我要得到
1 a1 c1
2 b1 a1
3 c1 b1
4 a1 c1
我做出来了,呵呵,大家学习一下吧
看下面的方法:
http://zhidao.baidu.com/question/94668020.html?si=2
谁把正确的写上来,就做最佳答案吧

select [字段1]
,(select [字段2] from [tab2] where [字段1] = [tab1].[字段2])
,(select [字段2] from [tab2] where [字段1] = [tab1].[字段2])
from [tab1]
-------------------------------------------------------
我这个 就能实现你说的结果

tab1 tab2
A B C A B
1 a c a a1
2 b a b b1
3 c b c c1
4 a c

其中大写的A、B、C为列
select a.A,(select B from tab2 where A=a.B) as B,(select B from tab2 where A=a.C) as C from tab1 a

假设你的表tab1字段为(字段1,字段2,字段3)
假设你的表tab2字段为(字段1,字段2)

修改第一列
update a set tab1.字段2=tab2.字段2 from tab1 left join tab2
on tab1.字段2=tab2.字段1

修改第二列
update a set tab1.字段3=tab2.字段2 from tab1 left join tab2
on tab1.字段3=tab2.字段1

LZ 你给的哪个连接上的答案不能用的!你的条件不是用内联或外联就能解决的,必须用子查询,因为你的要求比他的多,并且,你有2列!OK?其次在查询速度上来说,子查询要比内联或外联来的快,并且不会出现重复,或多行等现象,LZ明白?

select (select tab2.B from tab1,tab