日期:2014-05-18  浏览次数:20358 次

2个SQL的区别
SQL code

SELECT     SJ_CangChu.pinming as 品名, SJ_CangChu.xinghao as 型号, SJ_CangChu.tiaoma as 条码,sum(SJ_Order.num) as 数量
FROM         dbo.SJ_Order INNER JOIN
                      dbo.SJ_CangChu ON SJ_Order.outer_sku_id = SJ_CangChu.tiaoma
                      where SJ_Order.status='WAIT_SELLER_SEND_GOODS'
                      group by SJ_CangChu.pinming, SJ_CangChu.xinghao, SJ_CangChu.tiaoma
                      union all
SELECT     SJ_CangChu.pinming as 品名, SJ_CangChu.xinghao as 型号, SJ_CangChu.tiaoma as 条码,sum(SJ_Order.num) as 数量
FROM         dbo.SJ_Order INNER JOIN
                      dbo.SJ_CangChu ON SJ_Order.outer_iid = SJ_CangChu.tiaoma
                      where SJ_Order.status='WAIT_SELLER_SEND_GOODS'
                      group by SJ_CangChu.pinming, SJ_CangChu.xinghao, SJ_CangChu.tiaoma


SQL code

SELECT     SJ_CangChu.pinming as 品名, SJ_CangChu.xinghao as 型号, SJ_CangChu.tiaoma as 条码,sum(SJ_Order.num) as 数量
FROM         dbo.SJ_Order INNER JOIN
                      dbo.SJ_CangChu ON SJ_Order.outer_sku_id = SJ_CangChu.tiaoma or SJ_Order.outer_iid = SJ_CangChu.tiaoma
                      where SJ_Order.status='WAIT_SELLER_SEND_GOODS'
                      group by SJ_CangChu.pinming, SJ_CangChu.xinghao, SJ_CangChu.tiaoma



SJ_Order的新旧2个字段对应(outer_sku_id ,SJ_Order.outer_iid )分别对应SJ_CangChu.tiaoma 
这2个SQL有什么区别

------解决方案--------------------
结果几乎一样,只不过一个是or条件,一个是用的union all.
如果把union all改为union 则结果一模一样了.

不过貌似用or比较好.