为什么我在现场列表中获得未知列?

发布于 2025-01-23 15:15:54 字数 509 浏览 0 评论 0原文

运行此命令时,我在“字段列表”中获取未知列“订单”

我正在尝试获取带有订单数量的客户列表,以及用于类型的新列。如果客户有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时,正确的术语是什么?

When I run this command, I get the Unknown column 'Orders' in 'field list'

I am trying to get customer list with number of orders, and a new column for type. If the customer has more than 10 orders. It is a big buyer etc.

 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

Also what is the correct term when you use select in the column section of my query?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难理解 2025-01-30 15:15:54

我认为这对您有用。

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;

在“列列表中”中的选择仅被视为一个子查询。

I think this will work for you.

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;

The SELECT in the column list is just considered a subquery.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文