title: BigQuery - Export query results to local file/Google storage
body: <p>I want to export query results from BigQuery to local file/Google storage.</p>
  <p>I tried 'bq extract' command but it doesn't allow query as input.</p>
  <pre><code>Usage: bq extract &lt;source_table&gt; &lt;destination_uris&gt;
  </code></pre>
  <p>I don't want to extract the whole table as the table contains many columns which are not required and I need to aggregate the data.</p>
  <p>As of now, the only workaround I could find is to create a table using the 'bq query' command and use the 'bq extract' to extract the data.</p>
  <p>I'm looking for any better way to achieve this by doing something like below.</p>
  <pre><code>bq extract 'select dept_id,sum(sal) from temp.employee 
                                   group by dept_id' 'gs://XXXX/employee.csv'
  </code></pre>