Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
120 views
in Technique[技术] by (71.8m points)

java - How to find maximum date for every product in a list in Drools

I have a list of products with start and end dates, and I have to create a set of rules where I need to work on products one by one to find out their maximum date. For example,

Product(id=1, category=1, start=1/1/20, end=12/31/20)
Product(id=1, category=1, start=1/1/21, end=12/31/21)
Product(id=1, category=1, start=1/1/22, end=12/31/22)
Product(id=1, category=2, start=1/1/23, end=12/31/23)
Product(id=2, category=1, start=1/1/20, end=12/31/20)
Product(id=2, category=1, start=1/1/21, end=12/31/21)
Product(id=2, category=2, start=1/1/22, end=12/31/22)
Product(id=2, category=2, start=1/1/23, end=12/31/24)
Product(id=3, category=1, start=1/1/20, end=12/31/20)
Product(id=3, category=1, start=1/1/21, end=12/31/21)
...

So I need to pick the rows for every product id and category with the maximum end date. How can I do this in Drools?

I've tried this, but I am doubtful if this is correct.

Product($start:start, $cat:category, $id : id)
not(exists(Product(start>$start,category==$cat,id==$id)))

I am afraid it might be selecting products when their category and id values are unequal. How can I correct this rule?

question from:https://stackoverflow.com/questions/65927671/how-to-find-maximum-date-for-every-product-in-a-list-in-drools

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...