我想访问 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
那么怎么解决呢?对不起我的英语。
最佳答案
错误在这里:
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
或(重新定位右括号):
ON (tbl_customer_service.service_id = tbl_service.service_id
AND tbl_customer_service.customer_id = tbl_customer.customer_id)
关于mysql - on 子句 MySQL 中的未知列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25497430/