SQL语句练习实例之五 WMS系统中的关于LIFO或FIFO的问题分析
where s2.rcvdate>=s1.rcvdate
-@orderqty end
----2011-8-8 110 *8
--------
--按LIFO后进先出,就是后购入的存货先发出,所以,先发10日进货的10件,再发3日进货的20件,最后发1日进货的5件,发出成本共为:10*8+20*15+5*10=430元
drop view costfifo
from fifo as l
go
insert stock
----2011-7-7 75*17
as
select 8,'10561122','2011-8-8',110,8
as
and w1.qty>=w2.qty
--如货物A:本月1日购买10件,单价10元/件,3日购买20件,单价15元/件;10日购买10件,单价8元/件。
create view LIFO
-----总成本为 4605
select s1.rcvdate,s1.unitprice,sum(s2.qty) as qty,sum(s2.qty*s2.unitprice) as totalcost
select sum(unitprice*qty)/SUM(qty) as unitprice from stock
---LIFO: Last in, First out.后进先出。
go
-----'2011-3-3',35*15
select @pickqty,totalpick,bin1,qty1,bin2,qty2,bin3,qty3
update stock set qty =case when @orderqty>=(select currqty from CurrStock as c where c.rcvdate=stock.rcvdate)
exec RemoveQty 20
and w2.qty>=w3.qty
----1.LIFO (后进先出)
where s2.rcvdate<=s1.rcvdate
---则看一下当前的单价,乘以多出来的数量,并减去它。
----计算机也很难很快处理。
go
-----就可以将总成本作为答案返回。如果订单止的数量比库存的多,什么也不返回。如果某一天的库存数量比订单数量多
go
---
select 7,'10561122','2011-7-7',75,17 union
where rcvdate= (select MAX(rcvdate) from stock)
where rcvdate=(select min(rcvdate) from lifo as l2 where qty>=300)
where s2.rcvdate<=s1.rcvdate
create proc RemoveQty
----
----------
select 1,'10561122','2011-1-1',15,10 union
--- '2011-2-2',25*12
---在仓储管理中经常会碰到的一个问题
复制代码 代码如下:
create view CurrStock--本月15日发货35件。
end
select 5,'10561122','2011-5-5',55,10 union
select distinct (w1.qty+w2.qty+w3.qty) as totalpick
-----'2011-5-5',55*10
-----'2011-7-7',65*17
drop view fifo
go
where w1.id not in (w2.id,w3.id)
go
go
----总成本为5480
-----
create view pickcombos
go
--------
from stock s1 ,stock s2
---------------
delete from stock where qty=0
drop table stock
then 0
-----'2011-4-4',45*20
----2使用当前的平均成本单价,一共有420,总成本为6530,平均每件的成本为15.55
where totalpick=(select MIN(totalpick) from pickcombos where totalpick>=@pickqty)
create proc OverPick
rcvdate datetime not null,
,SUM(case when s2.rcvdate<=s1.rcvdate then s2.qty else 0 end) as CurrQty
---使用最小的仓库可以为订单的装卸工人带来最小的工作量,使用最大的仓库,则可以在仓库中清理出更多的空间
unitprice money not null
-------例如:对于这组数据,你可以使用(1,2,3,4,5,6,7)号仓库也可以使用(5,6,7,8)号仓库中的货物来满足订单的需求。
go
---
else (select currqty from CurrStock as c3 where c3.rcvdate=stock.rcvdate)
select 2,'10561122','2011-2-2',25,12 union
group by s1.rcvdate,s1.unitprice
drop proc OverPick
as
articleno varchar(20) not null,
drop view lifo
select s1.rcvdate,s1.unitprice,sum(s2.qty) as qty,sum(s2.qty*s2.unitprice) as totalcost
--select -3,'1900-1-1',0,0
as
---所以有了“贪婪算法”,这个算法算出来的常常是近乎最优的。这个算法的核心就是“咬最大的一口”直到达到或超越目标。
then stock.qty
-----在发货之后,实时更新库存表
--
create view costFIFO
go
drop proc RemoveQty
----
drop view pickcombos
from stock s1 ,stock s2
@orderqty int
as
exec OverPick 180
as
where rcvdate=(select max(rcvdate) from lifo as l2 where qty>=300)
-------还有一个问题,如何使用空间最小或最大的仓库中的货物来满足订单,假设仓库不是顺序排列,你可以按钮希望的顺序任意选择满足订单。
select (totalcost-((qty-300)*unitprice )) as cost
@pickqty int
,case when w1.id<0 then 0 else w1.id end as bin1 ,w1.qty as qty1,
select (totalcost-((qty-300)*unitprice )) as cost
as
from stock w1,stock w2, stock w3
go
-----'2011-6-6',65*30
)
select unitprice from stock
go
----2011-5-5 50*10
-----2.FIFO(先进先出)
select -2,'10561122','1900-1-1',0,0
as
-----找出满足订单的、足够存货的最近日期。如果运气好的话,某一天的库存数量正好与订单要求的数字完全一样
begin
---1.使用存储过程来找出满足或接近某一数量的挑选组合
---成本视图
复制代码 代码如下:
if(@orderqty>0)when @orderqty<(select prvqty from CurrStock c2 where c2.rcvdate=stock.rcvdate)
insert stock
if(@pickqty>0)
from stock s1 ,stock s2
(Id int not null primary key,
----这个就是装箱问题,它属于NP完全系统问题。对于一般情况来说,这种问题很难解决,因为要尝试所有的组合情况,而且如果数据量大的话,
end
----
---- '2011-1-1',15*10
case when w2.id<0 then 0 else w2.id end as bin2,w2.qty as qty2
and w2.id not in (w1.id,w3.id)
----1使用当前的替换成本,2011-8-8时每件产品的成本为8,就是说你这300件产品,成本价值为2400
---FIFO: First in, First out.先进先出。
三、使用“贪婪算法”进行订单配货
create view costLIFO
Create table stock
----此时如果在2011-8-8卖出300件产品,那么应该如何计算库存销售的价值呢?
from pickcombos
复制代码 代码如下:
--1. 第一个技巧,要在表中插入一些空的哑仓库,如果你最多需要n次挑选,则增加n-1个哑仓库select -1,'10561122','1900-1-1',0,0 union
二、示例
go
qty int not null,
drop view costlifo
group by s1.rcvdate,s1.unitprice
go
select s1.rcvdate,SUM(case when s2.rcvdate>s1.rcvdate then s2.qty else 0 end) as PrvQty
---下面这些查询和视图只是告诉我们库存商品的库存价值,注意,这些查询与视图并没有实际从库存中向外发货。
select 3,'10561122','2011-3-3',35,15 union
create view FIFO
----2011-6-6 65*30
drop view CurrStock
select 6,'10561122','2011-6-6',65,30 union
select 4,'10561122','2011-4-4',45,20 union
group by s1.rcvdate,s1.unitprice
--------
--按FIFO先进先出,就是先购入的存货先发出,所以,先发1日进货的10件,再发3日进货的20件,最后发10日进货的5件,发出成本共为:10*10+20*15+5*8=440元。
select * from stock
from lifo as l
begin
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://www.juheyunku.com/sql/mssql/1242.shtml
相关文章
热门TAG
命令 权重 外链 企业网站 白帽 php 织梦教程 dedecms修改内容 javascript 织梦 功能 标签 调用 详解 服务器 网站流量 实例解析 Dedecms 织梦cms HTML tags标签 python jquery教程 jquery windows SEO优化 蜘蛛 搜索引擎 网站收录 JSP最新文章
-
sql server 关于设置null的一
时间:2020-12-28
-
详解SQL游标的用法
时间:2020-12-27
-
vs code连接sql server数据库步
时间:2020-12-27
-
图书管理系统的sqlserver数
时间:2020-12-25
-
详解SQL 通配符
时间:2020-12-25
-
sql四大排名函数之ROW_NUM
时间:2020-12-25
-
SQLServer数据库处于恢复挂
时间:2020-12-24
-
Win10 64位安装个人版SQL20
时间:2020-12-24
热门文章
-
sqlserver中查询横表变竖表的sql语句简析
时间:2020-12-08
-
关于SQL Server查询语句的使用
时间:2020-12-13
-
SQL Server简单模式下误删除堆表记录恢复方
时间:2020-12-12
-
MSSQL教程_mssql数据库教程_MSSQL基础教程_第
时间:2020-12-13
-
详解SQL游标的用法
时间:2020-12-27
-
sql server 关于设置null的一些建议
时间:2020-12-28
-
jdbc连接sql server数据库问题分析
时间:2020-12-10
-
mssql关于一个表格结构的另外一种显示(表
时间:2020-12-11
-
SQL Server数据库入门学习总结
时间:2020-12-10
-
使用SqlBulkCopy时应注意Sqlserver表中使用缺
时间:2020-12-09
