I have the following tables:
Order
----
ID (pk)
OrderItem
----
OrderID (fk -> Order.ID)
ItemID (fk -> Item.ID)
Quantity
Item
----
ID (pk)
How can I write a query that can select all Orders that are at least 85% similar to a specific Order?
I considered using the Jaccard Index statistic to calculate the similarity of two Orders. (By taking the intersection of each set of OrderItems divided by the union of each set of OrderItems)
However, I can't think of a way to do so without storing the computed Jaccard Index for each possible combination of two Orders. Is there another way?
Also, is there a way to include the difference in Quantity of each matched OrderItem into account?
Additional Info:
Total Orders: ~79k
Total OrderItems: ~1.76m
Avg. OrderItems per Order: 21.5
Total Items: ~13k
Note
The 85% similarity number is just a best guess at what the customer actually needs, it may change in the future. A solution that works for any similarity would be preferable.