title: In SQL, how to get two different string values to do an aggregate function?
body: <p>Write a query to get the click-through rate per app in 2019. The schema of the events table is <strong>app_id</strong> (integer), <strong>event_id</strong> (string: &quot;impression&quot;, &quot;click&quot;, and <strong>timestamp</strong> (datetime). My query is below, but not sure how to filter by impression or click to calculate the click-through rate.</p>
  <pre><code>SELECT app_id, COUNT(event_id = ‘click’ ) / COUNT (event_id = ‘impression’) as click_through_rate
  FROM events 
  WHERE  EXTRACT(YEAR from timestamp) = 2019
  GROUP BY app_id
  ORDER BY click_through_rate DESC
  </code></pre>