How to rewrite the query in ActiveRecord?

Please help to rewrite the query in the view and ActiveRecord

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

I do not understand how to specify a dynamic condition in a subquery a1.campaign_id = a.campaign_id AND a1.`action`=10
April 3rd 20 at 17:14
0 answer

Find more questions by tags Yii