I am trying to create a variable that counts the number of occurrences in a row and sets them as a variable, depending on the particular value of 'action_type'
SELECT COUNT(v.visits_id) visits,s.source_type source,COUNT(CASE WHEN a.action_type=2) sale,COUNT(CASE WHEN a.action_type=1) contact FROM visits v
JOIN sources s ON v.source_id=s.source_id
JOIN actions a ON a.source_id=s.source_id
GROUP BY source ORDER BY visits DESC
So in this scenario I would want to be creating two variables for each row called sale and contact, which would have counted the occurrences when action_type=1 or action_type=2
How is this achieved?