select a.supp_id,a.mcode,b.factory_id,b.price.b.EffectDate                  
from a,b
where a.id=b.MtSuppPriceM_ID and b.EffectDate<'2001-11-1'
   and b.EffectDate = 
   (select max(EffectDate) as EffectDate 
    from b  t1 
    where t1.MtSuppPriceM_ID =a.id and b.factory_id=t1.factory_id 
          and  t1.MtSuppPriceM_ID <'2001-11-1')

解决方案 »

  1.   

    To:ICevi Tks
       不过你的代码中有几个笔误,更改如下:
    Select A.Supp_ID,A.MCode,B.Factory_ID,B.Price,B.EffectDate                  
      From MtSPM A,MtSPD B
      Where A.ID=B.MtSuppPriceM_ID And B.EffectDate<='2001-11-1'
            And B.EffectDate = (Select Max(EffectDate) As EffectDate 
                                From MtSPD T1
                                Where T1.MtSuppPriceM_ID =A.ID And B.Factory_ID=T1.Factory_ID
                                      And T1.EffectDate <='2001-11-1')
    稍后给分你,请查收
      

  2.   

    我觉得如果B表的主键ID字段如果和EffectDate时间是升函数,就是ID越大,EffectDate时间越新。可以取ID,应该快一些
    select a.supp_id,a.mcode,b.factory_id,b.price.b.EffectDate 
    from b left join a on a.id=b.MtSuppPriceM_ID 
    where b.ID in (select max(ID) from b where EffertDate <'2001-11-1' group by b.MtSuppPrivceM_ID ,b.factory_id)
      

  3.   

    To pxq:
       我觉得你说的有道理,且热心助人。准备给你一点分,聊表心意,却不能在此给出,是否还有其它方式可以给分?
    Tks