Market Basket Analysis

How many people bought both Product A and Product B?

Description

You can use market basket analysis to discover and understand customer purchasing behavior. For example, you can use it to answer questions such as:

  • How many people bought both Product A and Product B?
  • People who purchased Product A also generally buy which other products?

You can use the calculated result for your own recommendation system as well.

Sample Input

purchase
receipt_id item_id
1 31231
1 13212
2 312
3 2313
3 9833
4 1232
5 3211
... ...

Query


to view this query

Sample Output

item1 item2 cnt
583266 621056 3274
621056 583266 3274
31231 13212 2077
13212 31231 2077
2313 9833 953
9833 2313 953
3213 7891 953
7891 3213 953
1323 1111 762
1111 1323 762