gpt4 book ai didi

sql - 如何在左外连接中使用 CTE?

转载 作者:行者123 更新时间:2023-12-04 09:37:12 26 4
gpt4 key购买 nike

我正在尝试将公用表表达式加入现有表 (table1),如下所示。

select column1, column2 from table1

left outer join

;with cte as (
select column1, column2 from table2)

select column1, column2 from cte

on table1.column1 = cte.column1

错误是:
  • ';' 附近的语法不正确。
  • 关键字“on”附近的语法不正确。

  • 我究竟做错了什么?我应该为此任务使用 CTE 吗?

    最佳答案

    CTE 必须出现在查询的开头。

    with cte as (
    select column1, column2 from table2
    )
    select column1, column2 from table1
    LEFT JOIN cte
    on table1.column1 = cte.column1;

    关于sql - 如何在左外连接中使用 CTE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7707697/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com