当我尝试运行时,我收到错误“Not unique table / alias:'Caller'”,我不知道这意味着什么,但我觉得它与在不同的值上连接相同的两个表两次有关/ p>
SELECT Company_name,Contact_id, COUNT(Company_name) as nc
FROM Customer
JOIN Caller ON Customer.Company_ref = Caller.Company_ref
JOIN Caller ON Customer.Contact_id = Caller.Caller_id
JOIN Issue ON Caller.Caller_id = Issue.Caller_id
GROUP by Company_name, Contact_id
HAVING COUNT(Company_name) < 5
答案 0 :(得分:1)
如果您使用同一个表,则调用另一个名称或两个表以具有不同的名称...在这种情况下,为了避免混淆,请使用A和B.
SELECT Company_name,Contact_id, COUNT(Company_name) as nc
FROM Customer
JOIN Caller A ON Customer.Company_ref = A.Company_ref
JOIN Caller B ON Customer.Contact_id = B.Caller_id
JOIN Issue ON A.Caller_id = B.Caller_id
GROUP by Company_name, Contact_id
HAVING COUNT(Company_name) < 5
答案 1 :(得分:0)
您需要限定列名。我猜:
SELECT c.Company_name, c.Contact_id, COUNT(*) as nc
FROM Customer JOIN
Caller co
ON co.Company_ref = c.Company_ref JOIN
Caller ca
ON c.Contact_id = ca.Caller_id JOIN
Issue i
ON ca.Caller_id = i.Caller_id
GROUP by c.Company_name, c.Contact_id
HAVING COUNT(*) < 5;
只要查询中有多个表,就应该使用表别名和限定表名。
在没有看到数据的情况下,我不确定这是否有用。两个连接到不同键上的同一个表是可疑的。