title: BigQuery - counting number of events within a sliding time frame
body: <p>I would like to count the number of events within a sliding time frame.</p>
  
  <p>For example, say I would like to know how many bids were in the last 1000 seconds for the Google stock (GOOG).</p>
  
  <p>I'm trying the following query:</p>
  
  <pre><code>SELECT 
    symbol,
    start_date,
    start_time,
    bid_price,
    count(if(max(start_time)-start_time&lt;1000,1,null)) over (partition by symbol order by start_time asc) cnt
  FROM [bigquery-samples:nasdaq_stock_quotes.quotes] 
   where symbol = 'GOOG'
  </code></pre>
  
  <p>The logic is as follow: the partition window (by symbol) is ordered with the bid time (leaving alone the bid date for sake of simplicity).
  For each window (defined by the row at the "head" of the window) I would like to count the number of rows which have start_time that is less than 1000 seconds than the "head" row time.</p>
  
  <p>I'm trying to use max(start_time) to get the top row in the window. This doesn't seem to work and I get an error:</p>
  
  <pre><code>Error: MAX is an analytic function and must be accompanied by an OVER clause.
  </code></pre>
  
  <p>Is it possible to have two an analytic functions in one column (both count and max in this case)? Is there a different solution to the problem presented?</p>