Помогите пожалуйста переписать запрос в представление 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
Не пойму как задать динамическое условие во вложенном запросе a1.campaign_id = a.campaign_id AND a1.`action`=10