Answer the question
In order to leave comments, you need to log in
How to rewrite query in ActiveRecord?
Please help me to rewrite query into ActiveRecord view
SELECT a.campaign_id,
(SELECT COUNT(a1.`action`) FROM `action` a1 WHERE a1.campaign_id = a.campaign_id AND a1.`action`=10) pass,
(SELECT COUNT(a2.`action`) FROM `action` a2 WHERE a2.campaign_id = a.campaign_id AND a2.`action`=20) unique_pass,
(SELECT COUNT(a3.`action`) FROM `action` a3 WHERE a3.campaign_id = a.campaign_id AND a3.`action`=30) purchases
FROM `action` a
LEFT JOIN `campaign` c ON a.`campaign_id` = c.`id`
WHERE c.`user_id`=:user_id GROUP BY a.campaign_id
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question