如何将下面的语句中的 *= 改为 left joinselect a.drug_id,a.quantity as neednum,sum(isnull(b.quantity,0)) as stocknum 
from order_detail a,channel_stock b 
where a.order_no='11' and machine_id in ('k','h') and a.drug_id *= b.drug_id 
group by a.drug_id,a.quantity

解决方案 »

  1.   

    select a.drug_id,a.quantity as neednum,sum(isnull(b.quantity,0)) as stocknum 
    from order_detail a
        left join channel_stock b 
           on a.drug_id = b.drug_id 
    where a.order_no='11' and machine_id in ('k','h') 
    group by a.drug_id,a.quantity
      

  2.   

    *= 和left join 是等价的吗?
    我这查出来的结果不一样啊
    ×=:
    30007                2 16
    30015                2 0
    left join:
    30007                2 16
      

  3.   

    select a.drug_id,a.quantity as neednum,sum(isnull(b.quantity,0)) as stocknum 
    from order_detail a
        left join channel_stock b 
           on a.drug_id = b.drug_id 
             and a.order_no='11' and machine_id in ('k','h') 
    group by a.drug_id,a.quantity
      

  4.   

    在早期的 Microsoft® SQL Server™ 2000 版本中,使用 *= 和 =* 在 WHERE 子句中指定左、右外部联接条件。有时,该语法会导致有多种解释的不明确查询。FROM 子句中指定遵从 SQL-92 的外部联接,不会导致上述不确定性。因为 SQL-92 语法更为精确,所以,本版中未包括有关在 WHERE 子句中使用旧的 Transact-SQL 外部联接语法的详细信息。以后的 SQL Server 版本可能不再支持该语法。任何使用 Transact-SQL 外部联接的语句都应改为使用 SQL-92 语法。SQL-92 标准支持 FROM 或 WHERE 子句中的内部联接规范。WHERE 子句中指定的内部联接不会出现与 Transact-SQL 外部联接语法相同的不确定性问题。