解决方案 »

  1.   

    这样写呢?select  *  from 订单表 a 
    inner join 箱唛表 b   on 
    (a.目的国= b.目的国 and a.订单尾号=b.订单尾号 and b.箱唛规则=【目的国+订单尾号】)  
    or  
    (a.目的国= b.目的国 and a.订单尾号<>b.订单尾号 and a.运输方式=b.运输方式 and  b.箱唛规则=【目的国+运输方式】)  
      

  2.   

    那么两种改法,简单该法是别抽箱唛规则字段,然后distinct去重复
    复杂点的是对你抽出来的结果集以订单编号分组做rownumber over partition by,然后取rownumber为1的一条数据
      

  3.   

    跟关联条件OR 没有任何关系。 即使一个关联满足条件1也满足条件2,Or连接起来也只能关联出1条,不会关联出两条,关联不是Union all。所以,你出现任何重复都只可能是,你的数据本身就有问题,关联结果有重复问题,绝对是你数据本身有问题。把你的数据贴出来看看吧。
      

  4.   

    --看你需求,是不能用 Or 的,这么写试试,union all 对应的字段不能用*,用啥你自己调节
    with t as (
    select  *  ,1 sort
    from 订单表 a 
    inner join 箱唛表 b   on (a.目的国= b.目的国 and a.订单尾号=b.订单尾号 and b.箱唛规则=【目的国+订单尾号】)  
    union all
    select  *  ,2 sort
    from 订单表 a 
    inner join 箱唛表 b   on (a.目的国= b.目的国 and a.运输方式=b.运输方式 and  b.箱唛规则=【目的国+运输方式】)  
    ),tt as (
    select *,rn=ROW_NUMBER(partition by a.订单编号 order by sort)
    from t 
    )
    select * from tt where tt.rn=1