I have a table with details regarding a user subscription(id, user_id, plan_id, product_id, amount..etc).
I wanted to get favourite plan and product by getting maximum occurance of an id (plan_id, product_id)
in a table column.
I was trying to use this Find most frequent value in SQL column. But didn't work out.
Here is my query for favorite plan:
$subs = Subscription::findBySql("SELECT plan_id, COUNT(plan_id) AS `value_occurrence` FROM subscription GROUP BY plan_id
ORDER BY `value_occurrence` DESC LIMIT 1");
I just need the maximum occurance of plan_id
and product_id
.
Thanks for any help.