find similar books based on purchased books based on book meta keywords

后端 未结 1 850
既然无缘
既然无缘 2021-01-24 00:55

As the title suggest i want to find similar books based on customer purchased books based on the meta keywords. Below query works but Ive been told this can be simplified.

<
1条回答
  •  -上瘾入骨i
    2021-01-24 01:33

    You can do this with joins:

    select bmk2.book
    from customer_books cb
    inner join book_meta_keyword bmk1 
        on  bmk1.book = cb.book
    inner join book_meta_keyword bmk2 
        on  bmk2.meta_keyword = bmk1.meta_keyword
        and bmk2.book <> bmk1.book
    where cb.customer = 1
    

    The query starts from books that customer 1 purchased, then bring the corresponding keywords, and finally get all other books that have any keyword in common.

    Notes:

    • If there are several matching keywords across books, then you will get duplicate in the resultset. In that case use select distinct

    • You don't need table book to get the result you want - if needed for some reason, you can bring it with one more join

    0 讨论(0)
提交回复
热议问题