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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…