读书人

问大家一个语句

发布时间: 2013-01-28 11:49:56 作者: rapoo

问大家一个语句,在线等
表A
a1 a2
10 1
11 1
12 1
20 2
21 2
22 2 等等
表B
b1 b2
1 one
2 two
10 ten
11 eleven
12 twelve
20 twenty
21 twenty one
22 twenty two
都是字符型,a1,a2都与b1有关联,现在要输出
两列c1 c2,显示的是a1,a2对应的b2字段。

select distinct c.b2,b.b2 
from (select a.a2,b.b2 from a,b where a.a1=b.b1) c,b
where c.a2=b.b1;

这是一种方法,我洗完从select 这里做好处理 from 。。。 left join 。。。(这里只写连接条件) sql
[解决办法]
/*
b2 b2
------------- ---------
ten one
eleven one
twelve one
twenty two
twenty one two
twenty two two

(6 行受影响)
*/

读书人网 >SQL Server

热点推荐