目标
我在hostname列上为每个客户(比如BRASILFOODS)执行一个计数器,我想要的是BRASILFOODS计数的并排。
查询

SELECT COUNT(*) hostname, customer
FROM tb_get_gap
LEFT JOIN tb_get_customers
ON tb_get_gap.customer = tb_get_customers.cust_cmdb WHERE tb_get_customers.customer = 'BRASILFOODS' and tb_get_gap.exception = 'NO';

输出
>[Error] Script lines: 1-4 --------------------------
 ERROR: column reference "customer" is ambiguous
 Line: 1

最佳答案

SELECT
    tgg.customer,                     -- 1
    COUNT(*)
FROM tb_get_gap tgg
LEFT JOIN tb_get_customers tgc
    ON tgg.customer = tgc.cust_cmdb
WHERE tgc.customer = 'BRASILFOODS'
    AND tgg.exception = 'NO'
GROUP BY tgg.customer                 -- 2

“模棱两可”是指,有一个标识符可以从多个来源获得。在这种情况下,两个表都包含一个名为customer的列。因此,可以通过添加表标识符或别名来指定要显示哪一个。
您正在使用聚合函数(COUNT(*))。似乎你想通过customer计数。因此在这种情况下,您需要按此列分组。

关于sql - 错误:列引用“客户”不明确,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57924463/

10-11 02:26
查看更多