ユーザID | 商品ID | ユーザの評価 |
---|---|---|
1 | 1 | 1 |
1 | 2 | 1 |
1 | 3 | 0 |
2 | 1 | 0 |
2 | 2 | 1 |
2 | 3 | 1 |
3 | 1 | 1 |
3 | 2 | 1 |
3 | 3 | 0 |
こんな感じのテーブルがあったとして、
例えば、商品2を買ったユーザに何をおすすめしたら良いかを取得する
select
group_concat(user_id), product_id, taste
from
taste
where
user_id
in (
select user_id from taste where product_id = 2 and taste = 1
) and taste = 1
and product_id <> 2
group by product_id
order by count(user_id) desc
limit 10;
ブログはじめました。
この記事の詳しい画像つきの解説ものせております!