title: Count(case when) redshift sql - receiving groupby error
body: <p>I'm trying to do a count(case when) in Amazon Redshift. </p>
  
  <p>Using this <a href="https://stackoverflow.com/questions/21288458/in-redshift-postgres-how-to-count-rows-that-meet-a-condition">reference</a>, I wrote: </p>
  
  <pre><code>select
  sfdc_account_key,
  record_type_name,
  vplus_stage,
  vplus_stage_entered_date,
  site_delivered_date,
  
  case when vplus_stage = 'Lost' then -1 else 0 end as stage_lost_yn,
  case when vplus_stage = 'Lost' then 2000 else 0 end as stage_lost_revenue,
  case when vplus_stage = 'Lost' then datediff(month,vplus_stage_entered_date,CURRENT_DATE) else 0 end as stage_lost_months_since,
  count(case when vplus_stage = 'Lost' then 1 else 0 end) as stage_lost_count
  
  
  from shared.vplus_enrollment_dim
  where record_type_name = 'APM Website';
  </code></pre>
  
  <p>But I'm getting this error: </p>
  
  <pre><code>[42803][500310] [Amazon](500310) Invalid operation: column "vplus_enrollment_dim.sfdc_account_key" must appear in the GROUP BY clause or be used in an aggregate function; java.lang.RuntimeException: com.amazon.support.exceptions.ErrorException: [Amazon](500310) Invalid operation: column "vplus_enrollment_dim.sfdc_account_key" must appear in the GROUP BY clause or be used in an aggregate function;
  </code></pre>
  
  <p>Query was running fine before I added the count. I'm not sure what I'm doing wrong here -- thanks!</p>