为什么我在字段列表中出现未知列?

Why am I getting Unknown column in field list?

当我 运行 这个命令时,我得到 Unknown column 'Orders' in 'field list'

我正在尝试获取包含订单数量的客户列表,以及一个新的类型列。如果客户有超过 10 个订单。是大买家等

 SELECT 
    customerTable.isActive,
    (SELECT 
            COUNT(*)
        FROM
            orderTable
        WHERE
            orderTable.customerId = customerTable.id) AS Orders,
    
    CASE
        WHEN Orders > 10 THEN 'Big buyer'
        WHEN Orders > 12 THEN 'Biggest buyer'
    END AS 'Type'
   
    FROM customerTable

另外,当您在我的查询的列部分中使用 select 时,正确的术语是什么?

我认为这对你有用。

SELECT 
    customerTable.isActive,
    @Orders := (SELECT COUNT(*)
                FROM orderTable
                WHERE orderTable.customerId = customerTable.id) AS Orders,
    CASE
        WHEN @Orders > 10 THEN 'Big buyer'
        WHEN @Orders > 12 THEN 'Biggest buyer'
    END AS 'Type'
FROM customerTable;

列列表中的SELECT只是一个子查询。