|
就是下面的这句:
SELECT o.id, o.物料ID, o.销售日期, i.采购单价, iif(i.总量<o.总量,i.总量,o.总量) - iif(i.结余>o.结余,i.结余,o.结余) AS 数量, o.销售单价, (o.销售单价-i.采购单价) *数量 AS 利润
FROM (SELECT id, 物料ID, 采购日期, 采购数量, 采购单价, (select sum(采购数量) from 采购表 where 物料ID=a.物料ID and id<=a.id) AS 总量, 总量-采购数量 AS 结余
FROM 采购表 AS a) AS i INNER JOIN (SELECT id, 物料ID, 销售日期, 销售数量, 销售单价, (select sum(销售数量) from 销售表 where 物料ID=a.物料ID and id<=a.id) AS 总量, 总量-销售数量 AS 结余
FROM 销售表 AS a) AS o ON (i.结余<o.总量) AND (i.总量>o.结余) AND (i.物料ID=o.物料ID)
ORDER BY o.id, i.id;
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|