title: Group by Calculated Field
body: <p>I have a dataset with a date, and some values attached to each date. I am aggregating information across accounts, and grouping by account and days active. I want to know how accounts behave on average. I do not care about the DATE, I care about DAYS ACTIVE, so that is where my problem is occurring. I'm trying to create a calculated field (num_days) that is, for each account, the number of days since they first entered the system. </p>
  
  <pre><code>SELECT Acct_ID, L_Type, Num_License, Num_Active, Q_Date - MIN(Q_Date) as Num_days
  FROM s.Table
  WHERE flag = 'N'
  GROUP BY Acct_ID, Num_days
  </code></pre>
  
  <p>That gives me the error "Invalid Identifier"</p>
  
  <p>I have been reading to just use the calculation again in the group by, so I tried</p>
  
  <pre><code>GROUP BY Acct_ID, Q_Date - MIN(Q_Date)
  </code></pre>
  
  <p>That gives an error "Group function not allowed here"</p>
  
  <p>How can I go about grouping by number of days? Thanks!</p>