title: SQL - CASE WHEN result outputting conflicting results
body: <p>I'm working to solve
  <a href="https://platform.stratascratch.com/coding/10065-find-whether-the-number-of-seniors-works-at-facebook-is-higher-than-its-number-of-usa-based-employees?python=" rel="nofollow noreferrer">https://platform.stratascratch.com/coding/10065-find-whether-the-number-of-seniors-works-at-facebook-is-higher-than-its-number-of-usa-based-employees?python=</a></p>
  <p>This is the query I've attempted to write:</p>
  <pre><code>SELECT CASE WHEN COUNT(CASE WHEN location = 'US' THEN 1 ELSE 0 END) &gt;
      COUNT(CASE WHEN is_senior = true THEN 1 ELSE 0 END) THEN 'More USA-based'
      ELSE 'More seniors' END AS what_do_we_have_more_of
  FROM facebook_employees
  
  Result: 'More seniors'
  </code></pre>
  <p>However, when I rewrite it with the conditions flipped around:</p>
  <pre><code>SELECT CASE WHEN COUNT(CASE WHEN is_senior = true THEN 1 ELSE 0 END) &gt;
      COUNT(CASE WHEN location = 'US' THEN 1 ELSE 0 END) THEN 'More seniors'
      ELSE 'More USA-based' END AS what_do_we_have_more_of
  FROM facebook_employees
  
  Result: 'More USA-based'
  </code></pre>
  <p>Can someone please explain why there is a discrepancy here? What is wrong with the query I've written?</p>
  <p>I know this problem can be solved with sub-queries but I wanted to try out a <code>CASE WHEN</code> approach specifically. Is this more efficient?</p>
  <p>Edit: the solution I wrote with sub-queries (works with conditions reversed)</p>
  <pre><code>WITH us_employees AS (
      SELECT id, location
      FROM facebook_employees
      WHERE location = 'US'
  ),
  
  senior_employees AS (
      SELECT id, is_senior
      FROM facebook_employees
      WHERE is_senior = true
  )
  
  SELECT CASE WHEN COUNT(location) &lt; COUNT(is_senior) THEN 'More seniors' ELSE 'More US-based' END AS what_do_we_have_more_of
  FROM us_employees u
  FULL JOIN senior_employees s
  ON u.id = s.id
  
  Result: 'More seniors'
  </code></pre>