I'm trying to figured out the best way to count sold products by a given date range on orders by a specific family.
These are my simplified models:
Order
placed_onOrderItem
order_id, product_id, amountProduct
family_idFamily
So, given now some dates, say d1
and d2
, I need to count how many Product
of a given Family
are in those Order
.
The desired output would be something like this:
# all these are products from the same family sold in the last week
[
{"product_24": 3435},
{"product_34": 566},
{"product_83": 422}
…
]
I know how to do it looping all over the orders, but I think there should be a better way.