我正在使用下面的脚本向我展示未来的cap_date和max_capacity ...以及子查询,向我显示比第一个select语句旧的last_date和last_qty。
select
trunc(gp.cap_date) cap_date, gp.max_capacity,
(select max(trunc(gp1.cap_date))
from GPS_CAPACITY gp1
where gp.plant = gp1.plant
and gp.work_center_no = gp1.work_center_no
and gp1.cap_date = (select max(gp2.cap_date)
from GPS_CAPACITY gp2
where gp.plant = gp2.plant
and gp.work_center_no = gp2.work_center_no
and gp2.cap_date < gp.cap_date)) last_date,
(select max(gp1.max_capacity)
from GPS_CAPACITY gp1
where gp.plant = gp1.plant
and gp.work_center_no = gp1.work_center_no
and gp1.cap_date = (select max(gp2.cap_date)
from GPS_CAPACITY gp2
where gp.plant = gp2.plant
and gp.work_center_no = gp2.work_center_no
and gp2.cap_date < gp.cap_date)) last_qty
from
GPS_CAPACITY gp
where
gp.plant = 'W'
and gp.work_center_no = 'HPKG'
and trunc(gp.cap_date) > trunc(sysdate)
此脚本的输出如下所示...
..。我想要做的是创建一个从'last_date‘开始的日期列表,并为每个日期显示一个等于last_qty的数量;一旦日期列表达到'cap_date',数量应该更改为max_capacity (日期应该在’cap_date_max_capacity‘之后7天运行,即
有什么想法吗?谢谢
发布于 2014-12-23 22:12:05
首先创建一个包含感兴趣日期范围的cal表。让我们用一个date类型列dt调用这个表。假设上面的表名为table_cap
现在做一个
select cal.dt, case when cal.dt<cap_date then qty else max_capacity end
from cal
inner join table_cap on
(table_cap.last_date <= cal.dt
and cal.dt < adddate(capdate, interval 7 day )
https://stackoverflow.com/questions/26533233
复制相似问题