DML语句
更新时间:2021-06-24
百度流式计算QUERY语句完全兼容SPARK/FLINK SQL查询语句,根据创建作业时指定的引擎类型来决定使用哪种引擎的查询语句。
INSERT INTO语句
语法
INSERT INTO tableName
QUERY语句
- 同一个作业中,仅支持一个DML语句。
- 不支持单独的QUERY语句,需要在INSERT INTO内操作查询。
示例
INSERT INTO Orders
SELECT * FROM Orders WHERE units > 1000;
QUERY语句
语法
SELECT语句 [ ORDER BY expression ( ASC | DESC ) ]
| QUERY语句 ( INTERSECT | UNION | EXCEPT | SETMINUS ) [ ALL ] QUERY语句
示例一
SELECT a,b as B FROM tableName
UNION
SELECT a,b as B FROM otherTableName
ORDER BY a DESC
SELECT语句
语法
SELECT [ distinct ] { * | projectItem [ , projectItem ] }
FROM tableExpression
[ WHERE booleanExpression ]
[ GROUP BY { groupItem [, groupItem ]* } ]
[ HAVING booleanExpression ]
示例一
SELECT * FROM tableName;
示例二
SELECT a,b as B FROM tableName;
WHERE语句
语法
SELECT { * | projectItem [, projectItem ]* } FROM tableExpression [ WHERE booleanExpression ]
说明
WHERE语句通过添加条件过滤SQL语句的结果集,多个条件之间可以用AND、OR关联。
示例
SELECT * FROM Orders WHERE units > 1000;
GROUP BY语句
语法
SELECT [ ALL | DISTINCT ] { * | projectItem [, projectItem ]* } FROM tableExpression [ WHERE booleanExpression ] [ GROUP BY { groupItem [, groupItem ]* } ]
说明
GROUP BY 语句用于结合聚合函数,根据一个或多个列对结果集进行分组。
示例
SELECT Customer,SUM(OrderPrice) FROM Orders
[GROUP BY Customer]
HAVING语句
语法
SELECT [ ALL | DISTINCT ]{ * | projectItem [, projectItem ]* }
FROM tableExpression
[ WHERE booleanExpression ]
[ GROUP BY { groupItem [, groupItem ]* } ]
[ HAVING booleanExpression ];
说明
HAVING语句一般与GROUP BY语句一起使用,用于过滤聚合函数的结果。
示例
SELECT Customer,SUM(OrderPrice) FROM Orders
WHERE Customer='Bush' OR Customer='Adams'
GROUP BY Customer
HAVING SUM(OrderPrice)>1500
ORDER BY语句
语法
SELECT [ ALL | DISTINCT ]{ * | projectItem [, projectItem ]* }
FROM tableExpression
[ ORDER BY expression ( [ ASC ] | DESC ) ];
说明
ORDER BY 语句用于根据指定的列对结果集进行排序,默认按照升序对记录进行排序。使用 DESC 关键字对记录进行降序排列。
示例
SELECT Company, OrderNumber FROM Orders ORDER BY Company