相关文章推荐
仗义的羽毛球  ·  PolarDBPostgreSQL版PL/S ...·  9 月前    · 
飞奔的口罩  ·  math - Distance ...·  1 年前    · 
开朗的开心果  ·  UUID.randomUUID().toSt ...·  1 年前    · 

sql server外部连接有多个条件或条件

0 人关注

使用Sql Server 2008,我们有一个连接两个表Customer和Customer_Info的查询,列看起来像

   visit_date
   customer_seq_num

Customer_Info

   customer_seq_num
   customer_detail_number
   customer_value

这个查询的连接看起来像

    Customer 
    left outer join Customer_Info 
        on Customer_Info.customer_seq_num = Customer.customer_seq_num 
        and Customer_Info.customer_detail_number = 31 
        and (
            (right(Customer_Info.customer_value,4)='8788' and month(visit_date)=2) or
            (right(Customer_Info.customer_value,4)='8808' and month(visit_date)=12)or
            (right(Customer_Info.customer_value,4)='8891' and month(visit_date)=9)

问题是,如果我按原样运行该查询,我得到400条记录。如果我把第一个条件从 "和部分 "中删除,也就是说,我注释掉

--(right(Customer_Info.customer_value,4)='8788' and month(visit_date)=2) or