表A finish_date 是合同的完成时间。
表B rq 是合同出库时间。
表C rq 是合同入库时间。
现在求:A. finish_date -B.rq>0   or   A.finish_date -C.rq>0  的条数。

解决方案 »

  1.   

    发货时间-出库时间〈0 可以表述为: 发货时间<出库时间
    发货时间-入库时间〈0 可以表述为: 发货时间<入库时间select a.hth  from  order_detail a join order_sell_data b on a.hth=b.hth and a.finish_date <b.rp
    union
    select a.hth from oder_detail a join data_product_indepot  c on a.hth=c.hth and a.finish_date< c.rp
      

  2.   

    select 表A.* from 表A a,表B b,表C c
    where a.主键 = b.主键 and a.主键 = c.主键 and datediff(d,A.finish_date,B.rq) < 0 and 
    datediff(d,A.finish_date,c.rq) >0