UNNEST expression references column which is neither grouped nor aggregated
<p>Google Analytics BigQuery tables are structured like this (Legacy SQL notations - only relevant fields are shown):</p>

<pre><code>visitId:                      INTEGER
hits:                         RECORD/REPEATED
hits.hour:                    INTEGER
</code></pre>

<p>On one such table, the following query works well:</p>

<pre><code>SELECT
  visitId,
  MIN(h.hour) AS firstHitHour
FROM
  `my-table.ga_sessions_20161122`, UNNEST(hits) AS h
GROUP BY
  visitId
</code></pre>

<p>But using this alternative syntax:</p>

<pre><code>SELECT
  visitId,
  (SELECT MIN(hour) FROM UNNEST(hits)) as firstHitHour
FROM
  `my-table.ga_sessions_20161122`
GROUP BY
  visitId
</code></pre>

<p>Triggers the following error:</p>

<blockquote>
  <p><strong>Error</strong>: UNNEST expression references column hits which is neither grouped nor aggregated</p>
</blockquote>

<p>I understand that <code>UNNEST(hits)</code> must be somehow grouped or aggregated, but since this column is an <code>array (repeated)</code>, what does it mean exactly?</p>

<p>If I try to "group the column <code>hits</code>", as requested, like this:</p>

<pre><code>(SELECT MIN(hour) FROM UNNEST(hits) as h GROUP BY h) as firstHitHour
</code></pre>

<p>Then I get a <code>Grouping by expressions of type STRUCT is not allowed</code> error.</p>

<p>How can this alternative syntax be corrected to produce the same result as the first one?</p>