title: Google Big Query SQL TOP/Max/Order by
body: <p>Here is my query that works:</p>
  <blockquote>
  <p>SELECT a_name, w_name, page_url, SUM(IF(result = 'WIN', 1, 0)) as Impressions,</p>
  <p>from TABLE_DATE_RANGE(v3_data.v3_,TIMESTAMP('2015-08-05'),TIMESTAMP('2015-08-07'))</p>
  <p>WHERE server =&quot;server1&quot; and w_id IN (1096, 1105, 1136,1153,1189,1209)</p>
  <p>GROUP EACH BY 1,2,3</p>
  <p>ORDER BY Impressions DESC</p>
  <p>limit 1000000</p>
  </blockquote>
  <p>Now my issue is I dont want to use a limit.</p>
  <p>What I would like to do is choose the top 1000 results from each w_id, ordered by the impressions.</p>
  <p>There are multiple w_ids and this query will be extended to multiple servers too.</p>
  <p>originally I thought id try:</p>
  <blockquote>
  <p>select top 1000 * from [code above] group by 1,2,3</p>
  </blockquote>
  <p>but top doesnt work like that in big query and if I did that it wouldnt choose the top 1000 for each w_id it would do it over the whole set, so I could get none of the results for w_id 1209 if they are all relatively small.</p>
  <p>I hope this is enough information, I've been given a lot of stick on here for being to vague, but im trying to give as much detail and be as logical as I can.
  Thanks in advance</p>