title: SELECT Failed. 3504: Selected non-aggregate values must be part of the associated group in v14.10.05.09 and not in v14.00.07.02
body: <p>There are totally 9 fields in the select clause of the query where 5 are direct fields. 2 of them are result of select query in the select clause and 2 more are from using the result from previous 2 fields used in case when statements. The SUM aggregate is applied on the last two columns. </p>
  
  <p>All the first 5 columns are listed in the group by clause.</p>
  
  <p>Query :</p>
  
  <pre><code>SELECT
  sub.a,sub.b,sub.c,Table1.d,Table1.e,
  
  (select x from table t1 where y=current_date) as f,
  
  (select z from table t1 where y=w) as g,
  
  sum(case when f=g then 1 else 0)) as h,
  
  sum(case when f+1=g then 1 else 0)) as i
  
  FROM Table1
  
  LEFT JOIN
  
  (SELECT a,b,c,l,m,n,o FROM Table2 INNER JOIN Table3 ON Table2.p=Table3.t)sub
  
  ON Table1.e = sub.l
  
  GROUP BY sub.a,sub.b,sub.c,Table1.d,Table1.e
  </code></pre>
  
  <p>The above query which works perfectly fine in Teradata v14.10.05.09 but fails with </p>
  
  <blockquote>
    <p>"SELECT Failed. 3504:  Selected non-aggregate values must be part of
    the associated group"</p>
  </blockquote>
  
  <p>in Teradata v14.00.07.02. </p>
  
  <p>Is this because of something introduced in the newer version that is causing the query to fail but run fine in older version?
  Or am I missing something?</p>
  
  <p>Thanks in Advance.</p>
  
  <p>This is the actual query that is giving the problem: <code>SELECT
    sub.key,sub.div,sub.reg_nm,tb_cal.calendar_yr,tb_cal.calendar_mth,
    (SEL  fiscal_yr FROM db1.tb_cal tb_cal WHERE calendar_dt=CURRENT_DATE) current_fy,
    (SEL fiscal_yr FROM db1.tb_cal tb_cal WHERE calendar_dt=clse_dt) clse_dt_fy,
    SUM(CASE WHEN current_fy=clse_dt_fy THEN sub.amt ELSE 0 END) cnt
  FROM db1.tb_cal tb_cal<br>
   LEFT JOIN(  SELECT
     tbl_a.key,tbl_a.stage,COALESCE(tbl_u.div, 'Un-assigned') div,COALESCE(tbl_u.reg_nm,'Un-assigned') reg_nm,tbl_a.clse_dt,tbl_a.amt
    FROM db_a.tbl_a tbl_a
    INNER JOIN  db1.tbl_u tbl_u<br>
     ON tbl_u.unit_key=tbl_a.unit_key
    WHERE tbl_a.ctg IN ('G','O','C','F','I') AND tbl_a.stage NOT IN ('R', 'D', 'N','A') AND tbl_a.ind = 0 
  )sub
  ON sub.clse_dt =  tb_cal.calendar_dt
  GROUP BY sub.key,sub.div,sub.reg_nm,tb_cal.calendar_yr,tb_cal.calendar_mth</code></p>