BigQuery 的窗口函数,官方称呼为 “分析函数”(官方文档链接)
语法上和常规 SQL 语法基本没有太大差异,如下所示:
analytic_function_name ( [ argument_list ] )
OVER { window_name | ( [ window_specification ] ) }
window_specification:
[ window_name ]
[ PARTITION BY partition_expression_list ]
[ ORDER BY expression [{ ASC | DESC }] [, ...] ]
[ window_frame_clause ]
window_frame_clause:
{ ROWS | RANGE }
{
{ UNBOUNDED PRECEDING | numeric_expression PRECEDING | CURRENT ROW }
|
{ BETWEEN window_frame_boundary_start AND window_frame_boundary_end }
}
window_frame_boundary_start:
{ UNBOUNDED PRECEDING | numeric_expression { PRECEDING | FOLLOWING } | CURRENT ROW }
window_frame_boundary_end:
{ UNBOUNDED FOLLOWING | numeric_expression { PRECEDING | FOLLOWING } | CURRENT ROW }
上述比较值得关注的在于,window_frame_clause 这表明 BigQuery 中也提供了窗口函数子句。