我有个sql,冥思苦想写不出来比如说 A表中 两个字段 name ,qty 
      B表中 两个字段 name qty
a.name=b.name
如果通过a.name串到B表中 没此资料 ,b.qty就显示0 最后结果展示 a.name,a.qty,b.qty

解决方案 »

  1.   

    select a.name,a.qty,nvl(b.qty,0) b.qty
    from a,b
    where a.name = b.name(+)
      

  2.   

    另一种写法
    SELECT A.NAME, A.QTY, NVL(B.QTY, 0) B.QTY
      FROM A
      LEFT JOIN B ON A.NAME = B.NAME
      

  3.   

    建议楼主先去找本标准SQL的基础书好好读读!
      

  4.   


    create table a as
           select 'tom' name,150 qty from dual union all
           select 'makes',120 from dual union all
           select 'scott',122 from dual;
    --
    create table b as
           select 'tom' name,'黑龙江省齐齐发哈尔市' qty from dual union all
           select 'makes','云南楚雄市' from dual;
    --
    SQL> select a.name,a.qty,nvl(b.qty,0) b_qty
      2  from a,b
      3  where a.name=b.name(+);
    /*
    NAME         QTY B_QTY
    ----- ---------- --------------------
    tom          150 黑龙江省齐齐发哈尔市
    makes        120 云南楚雄市
    scott        122 0
    */
      

  5.   

    先楼上的连接,然后在对你的可能为空的字段时行判断。如果为NULL的时候返回个0就行了。