欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

HQL 写法 SQL 

程序员文章站 2022-07-12 10:51:11
...
HQL BNF 
query: 
    [selectClause] fromClause [whereClause] [groupByClause] [havingClause] [orderByClause]; 

selectClause: 
    SELECT DISTINCT? selectedPropertiesList | ( NEW className OPEN selectedPropertiesList CLOSE );; 

fromClause: 
    FROM className AS? identifier (  ( COMMA className AS? identifier ); | ( joinType path AS? identifier ); );*; 

joinType: 
    ( ( 'left'|'right' 'outer'? ); | 'full' | 'inner' );? JOIN FETCH?; 

groupByClause: 
    GROUP_BY path ( COMMA path );*; 

orderByClause: 
    ORDER_BY selectedPropertiesList; 

havingClause: 
    HAVING logicalExpression; 

whereClause: 
    WHERE logicalExpression; 

selectedPropertiesList: 
    ( path | aggregate ); ( COMMA path | aggregate );*; 

aggregate: 
    ( aggregateFunction OPEN path CLOSE ); |  ( COUNT OPEN STAR CLOSE ); |  ( COUNT OPEN DISTINCT | ALL path CLOSE );; 

aggregateFunction: 
    COUNT | 'sum' | 'avg' | 'max' | 'min'; 

logicalExpression: TODO! 

expression: TODO! 

collection: ( OPEN query CLOSE ); | ( 'elements'|'indices' OPEN path CLOSE );; 

quantifiedExpression: 'exists' | ( expression 'in' ); | ( expression OP 'any' | 'some' ); collection; 

compoundPath: path ( OPEN_BRACKET expression CLOSE_BRACKET ( '.' path );? );*; 

path: identifier ( '.' identifier );*; 

className: path; 

OP: EQ | LT | GT | LE | GE | NE | SQL_NE | LIKE; 

AS: 'as'; 
DISTINCT: 'distinct'; 
ALL: 'all'; 
COUNT: 'count'; 
SELECT: 'select'; 
FROM: 'from'; 
JOIN: 'join'; 
FETCH: 'fetch' 
BY: 'by'; 
GROUP_BY: 'group' BY; 
ORDER_BY: 'order' BY; 
HAVING: 'having'; 
WHERE: 'where'; 
NEW: 'new'; 

LIKE: 'like'; 
EQ: '='; 
LT: '<'; 
GT: '>'; 
SQL_NE: "<>"; 
NE: "!=" | "^="; 
LE: "<="; 
GE: ">="; 

COMMA: ','; 

OPEN: '('; 
CLOSE: ');'; 
OPEN_BRACKET: '['; 
CLOSE_BRACKET: ']'; 

CONCAT: "||"; 
PLUS: '+'; 
MINUS: '-'; 
STAR: '*'; 
DIV: '/'; 

相关标签: SQL