我想访问MySQL中子查询中的字段,但是我收到一个未知列'var_customer_id' in 'on clause'
错误。这是我的代码:
SELECT *,
CONCAT(customer_phone_1, ', ', customer_phone_2) AS customer_phone,
CONCAT(customer_fax_1, ', ', customer_fax_2) AS customer_fax,
CONCAT(customer_email_1, ', ', customer_email_2) AS customer_email,
tbl_customer.customer_id AS var_customer_id,
(
SELECT
GROUP_CONCAT(tbl_service.service_name SEPARATOR ', ')
FROM
kuesioner_bbia.tbl_customer_service
INNER JOIN kuesioner_bbia.tbl_service
ON (tbl_customer_service.service_id = tbl_service.service_id )
AND tbl_customer_service.customer_id=var_customer_id
GROUP BY tbl_customer_service.customer_id
)
FROM tbl_customer
ORDER BY customer_id ASC
那么如何解决呢?抱歉我的英文。
答案 0 :(得分:2)
错误在于:
ON (tbl_customer_service.service_id = tbl_service.service_id )
AND tbl_customer_service.customer_id=var_customer_id
可以是以下内容(注意:我将var_customer_id
替换为tbl_customer.customer_id
):
ON (tbl_customer_service.service_id = tbl_service.service_id )
WHERE tbl_customer_service.customer_id = tbl_customer.customer_id
OR(重新定位右括号):
ON (tbl_customer_service.service_id = tbl_service.service_id
AND tbl_customer_service.customer_id = tbl_customer.customer_id)