使用count(列)作为x.count(列)mysql

时间:2015-11-16 21:00:24

标签: mysql

这是我的代码,我希望任何人都可以帮我解决我的问题。我的问题是c.count和p.count行。他们每个人都做不同的工作。

SELECT tablesite.name,
tablesite.family,
tablesite.phone_number,
job_list.job_name,
p.COUNT(action.service_provider_id) as positive,
n.COUNT(action.service_provider_id) as negative
FROM tablesite
INNER JOIN relation
on tablesite.id_user=relation.user_id
INNER JOIN job_list
on relation.job_id=job_list.job_id 

LEFT JOIN action p
ON tablesite.id_user=action.service_provider_id
AND action.vote !='' AND action.customer_comment =''

LEFT JOIN action n
ON tablesite.id_user=action.service_provider_id
AND action.vote !='' AND action.customer_comment !=''


GROUP BY name, family,job_name, phone_number

我不能使用p.count或n.count如何解决这个问题。

  

错误:#1630 - 功能p.COUNT不存在。检查参考手册中的“功能名称解析和解决方案”部分

1 个答案:

答案 0 :(得分:1)

在黑暗中刺,但基于别名至少返回同一个表名action

SELECT tablesite.name,
tablesite.family,
tablesite.phone_number,
job_list.job_name,
COUNT(p.service_provider_id) as positive,
COUNT(n.service_provider_id) as negative
FROM tablesite
INNER JOIN relation
on tablesite.id_user=relation.user_id
INNER JOIN job_list
on relation.job_id=job_list.job_id 

LEFT JOIN action p
ON tablesite.id_user=p.service_provider_id
AND p.vote !='' AND p.customer_comment =''

LEFT JOIN action n
ON tablesite.id_user=n.service_provider_id
AND n.vote !='' AND n.customer_comment !=''


GROUP BY name, family,job_name, phone_number