declare @a table(id int,[11] varchar(20))
insert into @a select 1,'eee'
insert into @a select 2,'www'
insert into @a select 3,'ddd'
insert into @a select 4,'eee'declare @b table(id int,aa varchar(20),bb int)
insert into @b select 1,'tt',5
insert into @b select 2,'rr',3
insert into @b select 5,'hh',1select 
    a.id,a.[11],b.aa,b.bb 
from 
    @a a
left outer join 
    @b b 
on 
    a.id=b.id and b.bb > 2
where 
    a.[11] ='eee' /*
id          11                   aa                   bb          
----------- -------------------- -------------------- ----------- 
1           eee                  tt                   5
4           eee                  NULL                 NULL
*/

解决方案 »

  1.   

    select a.id,a.11,b.aa,b.bb from a left outer join b 
    on a.id=b.id
    where a.11 ='eee' 
    and b.bb > 2 
    可以这样写吗,结果是什么?

    1  eee  tt   5
    4  eee null  null这样吗.
    ================================
    不是

    1  eee  tt   5
    要想得到你要的结果得这样
    select a.id,a.11,b.aa,b.bb from a left outer join b 
    on a.id=b.id and b.bb > 2 
    where a.11 ='eee' 
      

  2.   

    left outer join=left join 
    连接条件加 "on"
      

  3.   

    结果应该是 1  eee  tt   5
    不能写在where 中
      

  4.   

    为什么b.bb > 2写在WHERE中就只有一条记录了?想不通