title: Error 3625: Group by and may not contain aggregate functions
body: <p>I'm trying to do a calculation on a what-if basis, so I assumed I could've done this using the case when function. Such as:</p>
  
  <pre><code>SELECT                                                                                                          
  TRIM(EXTRACT(YEAR FROM business_date))||'Q'||TRIM((EXTRACT(MONTH FROM business_date)+2)/3) as year_qtr,                 
  case when orr_txt = '1' then  (sum(cast (rr9m as float)) / (sum(cast (total_observations as float)) - 0.5*sum(cast (lft as float)) )) end as  DR_1,
  case when orr_txt = '2' then  (sum(cast (rr9m as float)) / (sum(cast (total_observations as float)) - 0.5*sum(cast (lft as float)) )) end as  DR_2,
  case when orr_txt = '3' then  (sum(cast (rr9m as float)) / (sum(cast (total_observations as float)) - 0.5*sum(cast (lft as float)) )) end as  DR_3,
  avg(cast (dp as float)) as Pred_PD                                  
  
  FROM                                        
       raroc.pd_matrixRR a,                                       
       raroc.ccc_dp_sc  b,
       raroc.ratings_convert c                                        
  WHERE                                                                                                   
       start_orr_code in (1)
       and case when a.scorecard_group = 'BB' then 'Business Banking' else a.scorecard_group end= b.rating_sys
       and a.orr_txt = b.bacrr
       and a.orr_txt = c.bacrr_text
       and orr_txt not in ('9-', '10', '11', '12', 'NR')                                      
       and rating_sys_grp = 'Scorecard'
       --and a.orr_txt = '1'
       --and scorecard_group = 'Large Corporation'
       --and scorecard_group = 'Large Corporation_FI'
       --and scorecard_group = 'Middle Market'
       --and scorecard_group = 'BB'
       --and scorecard_group = 'GCSBB'
       --and scorecard_group = 'Real Estate'
        and scorecard_group = 'Individuals'                                       
        and scorecard_group not like 'Sove%'                                      
        and scorecard_group not like 'Lega%'
        --and year_qtr &lt; '2014Q2'                                                                                         
  group by 1,2,3,4                            
  ORDER BY 2,1
  </code></pre>
  
  <p>It apparently didn't compile and laughed at my logic. However, I'll get an error 3604 if I don't group it. The question is, how would I get about this in order to calculate the rate for category 1, 2, and 3.
  Much appreciated!</p>
  
  <p>SP</p>