SELECT
daf.id as affiliate_id,
daf.name as affiliate_name,
dal.name as allocation_name,
dal.id as allocation_id,
dal.allocation,dal.price
FROM
degreeamerica.affiliates daf,degreeamerica.allocations dal
JOIN
(select pap.lead_price,pap.live, pap.allocation_id,pap.affiliate_id from paul.affiliates_price pap) pafp
ON (dal.id=pafp.allocation_id and daf.id=pafp.affiliate_id)
ORDER BY daf.id;
问题:它在on子句中说未知列daf.id,虽然我在字段列表中有这个列请帮助!!!。
答案 0 :(得分:1)
JOIN
个链。一直切换到显式的JOIN
,它会起作用。
SELECT
daf.id as affiliate_id,
daf.name as affiliate_name,
dal.name as allocation_name,
dal.id as allocation_id,
dal.allocation,dal.price
FROM
(select pap.lead_price,pap.live, pap.allocation_id,pap.affiliate_id
from paul.affiliates_price pap) pafp
JOIN
degreeamerica.affiliates daf
ON (daf.id = pafp.affiliate_id)
JOIN
degreeamerica.allocations dal ON
ON (dal.id = pafp.allocation_id)
ORDER BY daf.id;
答案 1 :(得分:0)
尝试编写FROM
这样的句子:
FROM paul.affiliates_price pafp JOIN
degreeamerica.affiliates daf
ON daf.id = pafp.affiliate_id JOIN
degreeamerica.allocations dal
ON dal.id = pafp.allocation_id
子查询也是不必要的,它阻碍了索引的使用(在MySQL中)。
答案 2 :(得分:0)
您可以将affiliates_price
表'子查询用作FROM和WHERE clasue之间的表。它会以这种方式工作。
SELECT
daf.id as affiliate_id,
daf.name as affiliate_name,
dal.name as allocation_name,
dal.id as allocation_id,
dal.allocation,dal.price
FROM
degreeamerica.affiliates daf,
degreeamerica.allocations dal,
(select pap.lead_price,pap.live, pap.allocation_id,pap.affiliate_id from paul.affiliates_price pap) pafp
WHERE
dal.id=pafp.allocation_id and daf.id=pafp.affiliate_id
ORDER BY daf.id;