Help Center/ MapReduce Service/ Component Operation Guide (LTS)/ Using HetuEngine/ Common HetuEngine SQL Syntax/ HetuEngine DQL SQL Syntax/ WITH
Updated on 2025-03-17 GMT+08:00
WITH
The WITH clause defines the naming relationship of query clauses, which can flatten nested queries or simplify subquery statements.
For example, the following query statements are equivalent:
SELECT name, maxprice FROM (SELECT name, MAX(price) AS maxprice FROM fruit GROUP BY name) AS x; WITH x AS (SELECT name, MAX(price) AS maxprice FROM fruit GROUP BY name) SELECT name, maxprice FROM x;
- Multiple Subqueries
with t1 as(select name,max(price) as maxprice from fruit group by name), t2 as(select name,avg(price) as avgprice from fruit group by name) select t1.*,t2.* from t1 join t2 on t1.name = t2.name;
- WITH Chain Form
WITH x AS (SELECT a FROM t), y AS (SELECT a AS b FROM x), z AS (SELECT b AS c FROM y) SELECT c FROM z;
Parent topic: HetuEngine DQL SQL Syntax
What is your overall rating for this page?
0
1
2
3
4
5
6
7
8
9
10
Very dissatisfiedVery satisfied
Thank you very much for your feedback. We will continue working to improve the documentation.
The system is busy. Please try again later.