select a.物料编号,a.物料价格 as 变动前价格,a.采购日期 as 变动前日期,
b.物料价格 as 变动后价格,b.采购日期 as 变动后日期
from 表 a,表 b
where a.物料编号=b.物料编号
and b.采购日期=(select min (采购日期) from 表 where 物料编号=a.物料编号 and 采购日期>a.采购日期 and 物料价格<>a.物料价格)
序号不明白怎么回事?错了不管哈,哈哈,哈哈哈......
b.物料价格 as 变动后价格,b.采购日期 as 变动后日期
from 表 a,表 b
where a.物料编号=b.物料编号
and b.采购日期=(select min (采购日期) from 表 where 物料编号=a.物料编号 and 采购日期>a.采购日期 and 物料价格<>a.物料价格)
序号不明白怎么回事?错了不管哈,哈哈,哈哈哈......
where b.物料编号=a.物料编号 and b.采购日期=c.采购日期) 变动前价格,物料价格,采购日期
from table a
(select top 1 物料价格 from tablename where 采购订单号 = A.采购订单号 and 采购日期 < A.采购日期
order by 采购日期 desc) as 变动前价格,
(select max(采购日期) from tablename where 采购订单号 = A.采购订单号 and 采购日期 < A.采购日期
order by 采购日期 desc) as 日期,
A.物料价格 as 变动后价格,A.采购日期 as 日期 from tablename A
SELECT a.物料号, a.价格 AS 变动前价格, a.日期 AS 变动前日期, b.价格 AS 变动后价格,
b.日期 AS 变动后日期
FROM cgdd a INNER JOIN
cgdd b ON a.物料号 = b.物料号
WHERE (b.日期 =
(SELECT MIN(日期)
FROM cgdd
WHERE 物料号 = a.物料号 AND 日期 > a.日期 AND 价格 <> a.价格)) AND
(a.日期 =
(SELECT MAX(日期)
FROM cgdd
WHERE 物料号 = b.物料号 AND 日期 < b.日期 AND 价格 <> b.价格))