【发布时间】:2019-09-13 21:40:55
【问题描述】:
目标
我正在为每个客户(如 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
【问题讨论】:
-
两个表都有一个列
customer。SELECT语句无法决定您要显示哪一个。所以定义相关表:SELECT one_of_both_tables.customer -
并添加
GROUP BY one_of_both_tables.customer -
很好,谢谢! SELECT tb_get_gap.customer, COUNT(*) hostname FROM tb_get_gap LEFT JOIN tb_get_customers ON tb_get_gap.customer = tb_get_customers.cust_cmdb WHERE tb_get_customers.customer = 'FLEURY' and tb_get_gap.exception = 'NO' GROUP BY tb_get_gap.customer;>
标签: sql postgresql