搜索

首页  >  问答  >  正文

无效输入:WITH 在此上下文中不是有效语法

所以我有类似的请求

WITH customers_in_usa AS (
        SELECT 
           customerName, state
        FROM
           customers
        WHERE
           country = 'USA'
    ) SELECT 
        customerName
    FROM
        customers_in_usa
    WHERE
        state = 'CA'
    ORDER BY customerName;

但是在编写它时我发现了一个错误:“WITH 在这个位置上的输入无效”error_picture。你能帮我理解这段代码有什么问题吗?

P粉124070451P粉124070451479 天前519

全部回复(1)我来回复

  • P粉851401475

    P粉8514014752023-10-24 00:39:02

    WITHcustomers_in_usaAS 目前是无效的 MySQL 代码。 MySQL 将来将在 MySQL 版本 8 中支持 CTE。

    您可以重写 SQL 代码,这应该会产生相同的结果。

    SELECT 
        customerName
      , state
    FROM 
       customers 
    WHERE
       country = 'USA'
     AND
       state = 'CA'
    ORDER BY
       customerName

    回复
    0
  • 取消回复