create table test1
(
a1 varchar(10),
a2 varchar(10)
)
insert into test1 select '01','02' create table test2
(
b varchar(10),
name varchar(20)
b2 varchar(10)
)
insert into test2 select '01','机动车','25'
insert into test2 select '02','摩托车','8'
根据test1查询,要显示下面的结构(条件必须要有b2,也就是说b=01 and b2=25 才能查询出来时机动车)
==============================
机动车 摩托车
(
a1 varchar(10),
a2 varchar(10)
)
insert into test1 select '01','02' create table test2
(
b varchar(10),
name varchar(20)
b2 varchar(10)
)
insert into test2 select '01','机动车','25'
insert into test2 select '02','摩托车','8'
根据test1查询,要显示下面的结构(条件必须要有b2,也就是说b=01 and b2=25 才能查询出来时机动车)
==============================
机动车 摩托车
没明白楼主的意思..select name from test2 where b='01' and b2='25' ?
------------------------------------------------------------------------------
Blog: http://blog.csdn.net/tianlesoftware
网上资源: http://tianlesoftware.download.csdn.net
相关视频:http://blog.csdn.net/tianlesoftware/archive/2009/11/27/4886500.aspx
Q Q 群:62697716
from test1,test2 t1,test2 t2
where a1=t1.b and a2=t2.b
and t1.b=01 and t1.b2=25
问题说明越详细,回答也会越准确!参见如何提问。(提问的智慧)
2.但是a1=b可能有多条,必须还要判断test2.b2='8',才能取得a1的name
from test1 as e
test2 as f
where e.a1=f.b
and f.b2='8'
from test1 as e
test2 as f
where e.a1=f.b
and f.b2='8'
=================
要显示a1和a2的两个name