title: BigQuery SPLIT() and grouping by result
body: <p>Using <code>SPLIT()</code> &amp; <code>NTH()</code>, I'm splitting a string value, and taking the 2nd substring as the result. I then want to group on that result. However, when I use SPLIT() in conjunction with a GROUP BY, it keeps giving the error:</p>
  
  <pre><code>Error: (L1:55): Cannot group by an aggregate
  </code></pre>
  
  <p>The result is a string, so why is it not possible to group on it?</p>
  
  <p>For example, this works and returns the correct string:</p>
  
  <pre><code>SELECT NTH(2,SPLIT('FIRST-SECOND','-')) as second_part FROM [FOO.bar] limit 10
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/xQPlU.png" alt="enter image description here"></p>
  
  <p>But then grouping on the result does not work:</p>
  
  <pre><code>SELECT NTH(2,SPLIT('FIRST-SECOND','-')) as second_part FROM [FOO.bar] GROUP BY second_part limit 10
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/OrKWa.png" alt="enter image description here"></p>