SELECT查询语句概况
Syntax
SelectStmt
SelectStmt
::= ( NoTableSelectClause | SelectStmtFromTable)
NoTableSelectClause
::= 'SELECT' SelectExprList
SelectStmtFromTable
::= SelectStmtBasic 'FROM' TableRefs [WhereClause] [GroupByClause] [HavingClause] [WindowClause] [OrderByClause] [LimitClause]
JoinClause
::= TableRef JoinType 'JOIN' TableRef [OrderClause] 'ON' Expression
JoinType ::= 'LAST'
WhereClause
::= 'WHERE' Expression
GroupByClause
::= 'GROUP' 'BY' ByList
HavingClause
::= 'HAVING' Expression
WindowClause
::= ( 'WINDOW' WindowDefinition ( ',' WindowDefinition )* )
OrderByClause ::= 'ORDER' 'BY' ByList
ByList ::= ByItem ( ',' ByItem )*
ByItem ::= Expression Order
Order ::= ( 'ASC' | 'DESC' )?
WindowClauseOptional
::= ( 'WINDOW' WindowDefinition ( ',' WindowDefinition )* )?
WindowDefinition
::= WindowName 'AS' WindowSpec
WindowSpec
::= '(' WindowSpecDetails ')'
WindowSpecDetails
::= [ExistingWindowName] [WindowUnionClause] WindowPartitionClause WindowFrameClause [WindowExcludeCurrentTime] [WindowInstanceNotInWindow]
WindowUnionClause
:: = ( 'UNION' TableRefs)
WindowPartitionClause
::= ( 'PARTITION' 'BY' ByList )
WindowFrameClause
::= ( WindowFrameUnits WindowFrameExtent [WindowFrameMaxSize])
WindowFrameUnits
::= 'ROWS'
| 'ROWS_RANGE'
WindowFrameExtent
::= WindowFrameStart
| WindowFrameBetween
WindowFrameStart
::= ( 'UNBOUNDED' | NumLiteral | IntervalLiteral ) ['OPEN'] 'PRECEDING'
| 'CURRENT' 'ROW'
WindowFrameBetween
::= 'BETWEEN' WindowFrameBound 'AND' WindowFrameBound
WindowFrameBound
::= WindowFrameStart
| ( 'UNBOUNDED' | NumLiteral | IntervalLiteral ) ['OPEN'] 'FOLLOWING'
WindowExcludeCurrentTime
::= 'EXCLUDE' 'CURRENT_TIME'
WindowInstanceNotInWindow
:: = 'INSTANCE_NOT_IN_WINDOW'
SelectExprList
SelectExprList
::= SelectExpr ( ',' SelectExpr )*
SelectExpr ::= ( Identifier '.' ( Identifier '.' )? )? '*'
| ( Expression | '{' Identifier Expression '}' ) ['AS' Identifier]
TableRefs
TableRefs
::= EscapedTableRef ( ',' EscapedTableRef )*
TableRef ::= TableFactor
| JoinClause
TableFactor
::= TableName [TableAsName]
| '(' ( ( SelectStmt ) ')' TableAsName | TableRefs ')' )
TableAsName
::= 'AS'? Identifier
SELECT语句元素
SELECT语句元素
状态
说明
FROM
TableRefs
已支持
表示数据来源,数据来源可以是一个表(select * from t;
)或者是多个表JOIN (select * from t1 join t2;
) 或者是0个表 ( select 1+1;
)
仅支持LAST JOIN
表示数据来源多个表JOIN。OpenMLDB目前仅支持LAST JOIN。在Online Serving时,需要遵循Online Serving下OP的使用规范
Online Training 不支持
窗口子句用于定义一个或者若干个窗口。窗口可以是有名或者匿名的。用户可以在窗口上调用聚合函数来进行一些分析型计算的操作(sql agg_func() over window_name
)。在Online Serving时,需要遵循Online Serving下OP的使用规范
ORDER BY
Clause
不支持
标准SQL还支持OrderBy子句。OpenMLDB目前尚未支持Order子句。例如,查询语句SELECT * from t1 ORDER BY col1;
在OpenMLDB中不被支持。
Last updated