mysql - Efficient SQL query to find overlap between lists -


let's have mysql table order_items (idorder, iditem, amount) contains items people ordered web shop. want find orders similar order x finding other orders similar items in similar amounts.

here current approach:

select sql_calc_found_rows            sum(greatest(1, least(cown.amount, cother.amount))) hits,            cother.`idorder`            order_items cown            left join order_items cother on (                cother.`idorder` != 1                , cown.iditem = cother.iditem            )            cown.`idorder` = 1 , cother.idorder not null            group cother.idorder asc            order hits desc 

this selects items given order , left joins them items other orders. group other order id , sum amount of overlap between them.

is there more efficient way this?

it looks need recommendation engine. tricky implement in plain sql , not sure how reliable. starters have apache mahout project.

there nice example mahout , mysql can try available on github: https://github.com/jasebell/recommenderdemo , looks thing want.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -