子查询(多列)中的选定列未显示

时间:2015-07-01 19:25:29

标签: mysql sql database subquery mysql-workbench

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 join 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; 

pap.lead_price,pap.live,pap.allocation_id,pap.affiliate_id 这些列未显示在结果集中。请帮忙!!!

2 个答案:

答案 0 :(得分:1)

简答

,pafp.lead_price,pafp.live,pafp.allocation_id,pafp.affiliate_id

之前将Select添加到From的末尾

<强>建议

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,
    pap.lead_price, -- add the fields you want from paul.affiliates_price
    pap.live,
    pap.allocation_id,
    pap.affiliate_id 
FROM
    degreeamerica.affiliates daf 
    JOIN degreeamerica.allocations dal -- what are we joining on?
    -- why create a subquery with no filters? just join to table.
    JOIN paul.affiliates_price pap ON dal.id=pap.allocation_id 
        and daf.id=pap.affiliate_id
ORDER BY
    daf.id

答案 1 :(得分:1)

在父选择语句中添加这些列。 像

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,
       pafp.lead_price,
       pafp.live,
       pafp.allocation_id,
       pafp.affiliate_id 
       from degreeamerica.affiliates daf JOIN 
            degreeamerica.allocations dal JOIN
            (select        
                 pap.lead_price as lead_price,pap.live as live,
                  pap.allocation_id as allocation_id,
                  pap.affiliate_id  as affiliate_id
                 from paul.affiliates_price pap
            ) pafp on dal.id=pafp.allocation_id and daf.id=pafp.affiliate_id  
         order by daf.id;