22,209
社区成员
发帖
与我相关
我的任务
分享
--已入库未出库数据:到底是要得到已入库,但未出过库的商品名称呢?还是要得到商品现有库存?
--1、已入库,但未出过库的商品名称
select * from 入库数 a where not exists(select 1 from 出库表 b where a.产品=b.产品,a.名称=b.名称)
--2、得到各商品库存:
select a.产品,a.名称,库存=入库数-isnull(出库数,0) from
(select 产品,名称,入库数=sum(入库数) from 入库表 group by 产品,名称)a
left join
(select 产品,名称,出库数=sum(出库数) from 出库表 group by 产品,名称)b
on a.产品=b.产品,a.名称=b.名称
--已出库未开票数据:
--这样?
select * from 出库表 where not exists
(select 1 from 订单表 b,开票表 c where 订单号=a.订单号 and b.客户=c.客户)
--已开票未回笼数据:
select * from 开票表 a where not exists(select 1 from 回笼表 where 发票号=a.发票号)
--已入库出库开票回笼数据:入库出库 和 开票回笼这两两之间又通过什么字段关联?