Evidently there's two stages to this -- find the users who have previously ordered those same items, and find the items most commonly ordered by those users other than those items.
I expect that inserting the ordered items into a temporary table would be helpful.
You could find the users with code similar to ...
... and then find the most popular ordered items for those users with something like ...Code:Select username from orders where ordered_item in ( select ordered_item from temp_new_order ) group by username having count(distinct ordered_item) = (select count(*) from temp_new_order)
This may not be the best performing code, but at least it's a workable method to start with.Code:Select ordered_item from ( Select ordered_item, sum(ordered_qty) sum_qty From orders Where username in (previous query inserted here) and ordered_item not in (select ordered_item from temp_new_order) group by ordered_item order by 2 desc ) Where rownum <= 5




Reply With Quote