title: Error with aggregate function in a CASE statement and GROUP BY clause
body: <p>I have the following CTE that I am using in a larger query and I receive two different error messages based on how I group.  </p>
  
  <p>I am on Redash and using Amazon Athena.  I can group by tenant_id or I can group by <code>tenant_id</code> &amp; my case statement that is named <code>"active"</code>. Either way I will receive an error.</p>
  
  <pre class="lang-sql prettyprint-override"><code>active_billpay AS
    (SELECT o.tenant_id as tenant_id, CASE WHEN o.created_date &gt;= min(mbpc.created_date) 
       THEN true else false end as active
      FROM reporting.t_order o
      LEFT JOIN reporting.t_me_bill_pay_charge mbpc ON o.tenant_id = mbpc.tenant_id
        WHERE o.retired_date is null
          AND mbpc.retired_date is null
      GROUP by 1),
  </code></pre>
  
  <p>If I group by only tenant_id: </p>
  
  <blockquote>
    <p>Error running query: SYNTAX_ERROR: line 13:32: '(CASE WHEN
    ("o"."created_date" >= "min"("mbpc"."created_date")) THEN true ELSE
    false END)' must be an aggregate expression or appear in GROUP BY
    clause</p>
  </blockquote>
  
  <p>If I group by both tenant_id and active: </p>
  
  <blockquote>
    <p>Error running query: SYNTAX_ERROR: line 13:32: GROUP BY clause cannot
    contain aggregations or window functions:
    ["min"("mbpc"."created_date")]</p>
  </blockquote>
  
  <p>Thank you in advance.</p>