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')
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')
解决方案 »
- 求个SQL 函数的写法
- 多表连接及连接后统计的问题,在线等!
- sqlserver中随机选取n条记录的问题?
- 请教一个SQL的问题
- 请高手优化SQL语句
- sql中 查询一个字段中只有不同的才显示出来,相同的值就取一个,怎么实现啊?
- 大虾帮帮忙,100分求!急~~~
- 如何用数据库实现a地点到b地点的公交线路呢(类似于chinaquest的系统)给高分!
- 在Internet网上可以用ODBC连接到远程MSSQL70服务器上吗,如何连接??
- 触发器内锁的周期
- 我在安装完SQL SERVER后,打不开管理起,报错:管理单元初始化失败 名称 —无— CLICD:{001001001-1816-11D08EF500AA00C2C58F}.谢谢大侠
- 挑战极限:100多条记录,只有时间(年-月-日 时:分:秒)、数值2个字段,如何快速找到某一时间的记录?(ipman)
不过你的代码中有几个笔误,更改如下:
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')
稍后给分你,请查收
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)
我觉得你说的有道理,且热心助人。准备给你一点分,聊表心意,却不能在此给出,是否还有其它方式可以给分?
Tks