LoginSignup
3
4

More than 5 years have passed since last update.

SQLだけで商品をレコメンドしてみる

Last updated at Posted at 2017-11-21
ユーザ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;

ブログはじめました。
この記事の詳しい画像つきの解説ものせております!

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4