BigQuery - counting number of events within a sliding time frame -
i count number of events within sliding time frame.
for example, know how many bids in last 1000 seconds google stock (goog).
i'm trying following query:
select    symbol,   start_date,   start_time,   bid_price,   count(if(max(start_time)-start_time<1000,1,null)) on (partition symbol order start_time asc) cnt [bigquery-samples:nasdaq_stock_quotes.quotes]   symbol = 'goog'   the logic follow: partition window (by symbol) ordered bid time (leaving alone bid date sake of simplicity). each window (defined row @ "head" of window) count number of rows have start_time less 1000 seconds "head" row time.
i'm trying use max(start_time) top row in window. doesn't seem work , error:
error: max analytic function , must accompanied on clause.   is possible have 2 analytic functions in 1 column (both count , max in case)? there different solution problem presented?
try using range function.
select    symbol,    start_date,    start_time,    bid_price,    count(market_center) on (partition symbol order start_time range 1000 preceding) cnt   [bigquery-samples:nasdaq_stock_quotes.quotes]    symbol = 'goog'   order 2, 3     i used market_center counter, additional fields can used well.
note: range function not documented in bigquery query reference, it's standard sql function appears work in case
Comments
Post a Comment