Skip to content

Commit e85db35

Browse files
committed
find_category_recommendation_pairs.sql
1 parent fb9c2eb commit e85db35

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- Write your PostgreSQL query statement below
2+
WITH cte AS (
3+
SELECT pp.user_id, pp.product_id, pi.category
4+
FROM ProductPurchases pp
5+
LEFT JOIN ProductInfo pi ON pp.product_id = pi.product_id)
6+
SELECT c1.category category1,
7+
c2.category category2,
8+
COUNT(DISTINCT c1.user_id) customer_count
9+
FROM cte c1
10+
LEFT JOIN cte c2 ON c1.user_id = c2.user_id
11+
WHERE c1.category < c2.category
12+
GROUP BY c1.category, c2.category
13+
HAVING COUNT(DISTINCT c1.user_id) > 2
14+
ORDER BY customer_count DESC, c1.category, c2.category

0 commit comments

Comments
 (0)