英文:
Combine WITH AS and JOIN in Presto SQL
问题
In Presto SQL, you cannot use "WITH table_name AS (... JOIN ...)" directly. This might be specific to Presto SQL. To achieve your desired result, you can try a different approach.
英文:
For some reason, in presto sql, I cannot use "WITH table_name AS (... JOIN ...)". For instance:
WITH table_name AS
(SELECT att1 FROM table1
LEFT OUTER JOIN
SELECT att2 FROM table2
ON att1=att2)
SELECT
*
FROM
table_name
Gives syntax error. I've tried many combinations, unsuccessfully. I have no idea if it is common to most sql engines or just presto. Would anyone know how to do it ?
答案1
得分: 1
你的语法有问题。 应该是:
<!-- language: sql -->
WITH table_name AS (
SELECT t1.att1, t2.att2
FROM table1 t1
LEFT JOIN table2 t2
ON t1.att1 = t2.att2
)
SELECT *
FROM table_name;
一个查询/子查询应该只有一个 SELECT
子句。 此外,我已经添加了查询中的表别名,以便更容易阅读。
英文:
Your syntax is off. It should be:
<!-- language: sql -->
WITH table_name AS (
SELECT t1.att1, t2.att2
FROM table1 t1
LEFT JOIN table2 t2
ON t1.att1 = t2.att2
)
SELECT *
FROM table_name;
A single query/subquery should have only one SELECT
clause. In addition, I have added table aliases to the query to make it easier to read.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论