所以有点复杂。
我们在ERP系统中有一个“报告”。这就像来自几个表的大查询......但是,我猜它并不那么重要。我们有数千行。
这只是一个例子:
如何搜索“下一个传单号码”?因此,如果项目在传单 2015C 和 2016C 中,我想获得“扩展传单”。
这里的逻辑是:如果该项目在实际传单中 +1 = 那是一个“扩展传单”。
2015C
: 20
实际年份,15
是传单的编号。C
是传单的类型。
日期是从 2008 年到今天。所以我不能只计算价值(有很多项目有很多传单)。
也许有什么LAG/LEAD
?
现在我正在使用这个查询,但它不准确(自连接):
decode(null,
(select count(*)
from --my_actual_table g
where g.id = id
and g.place_of_delivery = place_of_delivery
and g.partner = partner
and g.date <= date and g.date >= date-22
group by g.id, g.place_of_delivery, g.partner
having count(*) > 1 ),
null,'Extended flyer')
有没有更好的方法来做到这一点?
我创建了一些表格,其中仅包含一列:传单。查询如下所示:
Select flyer,
case when to_number(substr(flyer,3,2))-to_number(substr(previous_flyer,3,2))=1 then 'Extended' else ' ' end
from
(
Select flyer,
LAG(flyer,1) over (order by flyer) as previous_flyer
from stackoverflow_table
)
检查它及其工作,我得到一个输出:
2015C
2017C
2018C Extended
2019C Extended
2021C
2023C
2024C Extended
2025C Extended
2027C
2029C
2030C Extended
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句