0

我在 mysql 中编写了一个查询,以从 job_input 表中获取所有记录,如果可以从 job_output 表中获取相应的输出记录。它给出了以下错误:

查询:select ji.* from job_inputas ji left join (select SUM(jo.O_Total) AS Total_Output, SUM(jo.O_XS) AS XS_Output, SUM(jo.O_S) AS ...

错误代码:1248 每个派生表都必须有自己的别名

以下是我的查询。我究竟做错了什么??

SELECT ji.* 
    FROM `job_input` AS ji LEFT JOIN
    (SELECT 
    SUM(jo.O_Total) AS Total_Output,
    SUM(jo.O_XS) AS XS_Output,
    SUM(jo.O_S) AS S_Output,
    SUM(jo.O_M) AS M_Output,
    SUM(jo.O_L) AS L_Output,
    SUM(jo.O_XL) AS XL_Output,
    SUM(jo.O_XXL) AS XS_Output,
    SUM(jo.O_Other) AS Other_Output FROM `job_output` AS jo GROUP BY jo.`Job_InputID`)
    ON jo.`Job_InputID`= ji.`Job_InputID`
4

1 回答 1

2

你需要把别名加入表吗?

SELECT ji.* 
    FROM `job_input` AS ji LEFT JOIN
    (SELECT 
    jo.`Job_InputID` AS JobID
    SUM(jo.O_Total) AS Total_Output,
    SUM(jo.O_XS) AS XS_Output,
    SUM(jo.O_S) AS S_Output,
    SUM(jo.O_M) AS M_Output,
    SUM(jo.O_L) AS L_Output,
    SUM(jo.O_XL) AS XL_Output,
    SUM(jo.O_XXL) AS XS_Output,
    SUM(jo.O_Other) AS Other_Output FROM `job_output` AS jo GROUP BY jo.`Job_InputID`) AS table2
    ON table2.JobID = ji.`Job_InputID`
于 2015-11-20T18:11:52.167 回答