例如有2个表
table1 表结构 id,name
table2 表结构 id,ct_point table1数据大概如下
[id],[name]
1  人员1
2  人员2
3  人员3
4  人员4
.......table2数据大概如下
[id],[ct_point]
1  100
3  35
.......我想搜索结果为[id],[name],[ct_point]
1  人员1    100
2  人员2    0
3  人员3    35
4  人员4    0也就是table1中的记录如果在table2里没有对应的数据的话
就给他默认为一个数值 0这个怎么查询啊

解决方案 »

  1.   

    select a.id,a.name,nvl(b.ct_point,0)
    from table1 a,table2 b
    where a.id=b.id(+)
      

  2.   

    谢谢,用这个语句可以
    不过我又加了个条件,就不行了
    table2 表结构 id,ct_point ,typeselect a.id,a.name,nvl(b.ct_point,0)
    from table1 a,table2 b
    where a.id=b.id(+) and b.type='1'
    这样就不行了,这个可以解决吗
      

  3.   

    select a.id,a.name,nvl(b.ct_point,0) 
    from table1 a,table2 b 
    where a.id=b.id(+) and b.type(+)='1' 
      

  4.   

    select t1.id,t2.name,nvl(ct_point,0) from table1 t1 ,table2 t2  where t1.id=t2.id(+)
    and t2.type(+) = '1'