IN / ALL / ANY子查询where子句中的未知列

时间:2015-03-21 07:51:26

标签: mysql

问题: 我知道它在MYSQL文档中记录在where where子句"别名"因为尚未填充where子句,所以无法使用。但我必须从where子句(IN条件)中获取与其他表值匹配的数据。

我也读了一些类似的帖子,但是这个帖子是完全不同的&大复杂的。我无法使用过去3天的努力。 它显示错误(根据文档除外)

UNKNOWN COLUMN" Ind_ID"在WHERE CLAUSE中

我必须同样匹配 FA_ID & PREFERRED_LOCATION_ID 字段

Select a.job_id, a.Employer_ID, a.Sub_user_id,  
Date_format(a.creation_on,'%d-%m-%Y') as Created_date, a.Job_type, 
a.Designation, a.Open_Positions, a.Job_Description, a.Min_age,  
a.Max_age, a.min_exp, a.max_exp, a.Hide_Salary,  a.company_name, 
a.About_Company, a.Contact_person_name, a.Contact_No, a.Refresh_type, 
a.Response_type,
(Select GROUP_CONCAT(DISTINCT g.Education ORDER BY pjedu.Education_ID 
    SEPARATOR ', ') user_education 
    from e_pj_edu pjedu
    INNER JOIN education g ON FIND_IN_SET(g.Edu_ID, pjedu.Education_ID) 
    where a.job_id = pjedu.Job_ID
) as Education_ID,

(Select GROUP_CONCAT(DISTINCT h.FA_description ORDER BY uf.FA_ID 
     SEPARATOR ', ') FA 
     from e_pj_fa uf 
     INNER JOIN functional_area h ON FIND_IN_SET(h.FA_ID, uf.FA_ID) 
     where a.Job_ID = uf.Job_ID
) as FA_ID,

(Select GROUP_CONCAT(DISTINCT i.Industry_description ORDER BY   
    ui.Industry_ID SEPARATOR ', ') Industry_ID 
    from e_pj_industry ui 
    INNER JOIN industry i ON FIND_IN_SET(i.Industry_ID, ui.Industry_ID)
    where a.Job_ID = ui.Job_ID
) as Ind_ID,

(Select GROUP_CONCAT(DISTINCT j.location_name ORDER BY 
    upl.Location_ID SEPARATOR ', ') Location_ID 
    from e_pj_locations upl 
    INNER JOIN locations j ON FIND_IN_SET(j.location_id, upl.Location_ID)
    where a.Job_ID = upl.Job_ID
) as Preferred_Location_ID,

(Select GROUP_CONCAT(DISTINCT uk.Keyword_Name  ORDER BY uk.Keyword_ID 
    SEPARATOR ', ') keyskills 
    from e_pj_keywords uk
    where a.Job_ID = uk.Job_ID
) as Keyword_Name,

GROUP_CONCAT(DISTINCT cc.salary_description ORDER BY cc.salary_ID 
SEPARATOR ', ') Min_salary, 

GROUP_CONCAT(DISTINCT dd.salary_description ORDER BY dd.salary_ID 
SEPARATOR ', ') Max_salary

from post_jobs a
    INNER JOIN user_salary cc ON FIND_IN_SET(cc.salary_ID, a.Min_salary)  
    INNER JOIN user_salary dd ON FIND_IN_SET(dd.salary_ID, a.Max_salary)
WHERE a.Designation LIKE '%MIS%' or a.company_name LIKE '%MIS%' 
    And a.max_exp <= 9 
    And a.Max_salary<=110 
    And Ind_ID IN (10001,10002,10004)
    And FA_ID IN(1001) 
group by a.job_id

2 个答案:

答案 0 :(得分:0)

我想到的第一件事就是将你的别名移动到外部查询的条件,即:

select * from ( 
   Select a.job_id ....
   WHERE a.Designation LIKE '%MIS%' or a.company_name LIKE '%MIS%' 
      And a.max_exp <= 9 
      And a.Max_salary<=110 
   group by a.job_id
) inner 
where 
Ind_ID IN (10001,10002,10004)
And FA_ID IN(1001) 

GL!

答案 1 :(得分:0)

发布有效的修订查询。可能这有助于某人像我一样浪费3天: - )

select * from (
            Select a.job_id, a.Employer_ID, a.Sub_user_id, Date_format(a.creation_on,'%d-%m-%Y') as Created_date, a.Job_type, a.Designation, a. 
            Open_Positions, a.Job_Description, a.Min_age, a.Max_age, a.min_exp, a.max_exp, a.Hide_Salary, a.company_name, a.About_Company, a.Contact_person_name, 
            a.Contact_No, a.Refresh_type, a.Response_type,
                (Select GROUP_CONCAT(DISTINCT g.Education ORDER BY pjedu.Education_ID SEPARATOR ', ') user_education 
                    from e_pj_edu pjedu
                    INNER JOIN education g ON FIND_IN_SET(g.Edu_ID, pjedu.Education_ID) 
                    where a.job_id = pjedu.Job_ID
                ) as Education_ID,
                (Select GROUP_CONCAT(DISTINCT h.FA_description ORDER BY uf.FA_ID SEPARATOR ', ') FA 
                    from e_pj_fa uf 
                    INNER JOIN functional_area h ON FIND_IN_SET(h.FA_ID, uf.FA_ID) 
                    where a.Job_ID = uf.Job_ID
                ) as FA_ID,
                (Select GROUP_CONCAT(DISTINCT i.Industry_description ORDER BY ui.Industry_ID SEPARATOR ', ') Industry_ID 
                    from e_pj_industry ui 
                    INNER JOIN industry i ON FIND_IN_SET(i.Industry_ID, ui.Industry_ID)
                    where a.Job_ID = ui.Job_ID
                ) as Ind_ID,
                (Select GROUP_CONCAT(DISTINCT j.location_name ORDER BY upl.Location_ID SEPARATOR ', ') Location_ID 
                    from e_pj_locations upl 
                    INNER JOIN locations j ON FIND_IN_SET(j.location_id, upl.Location_ID)
                    where a.Job_ID = upl.Job_ID
                ) as Preferred_Location_ID,
                (Select GROUP_CONCAT(DISTINCT uk.Keyword_Name  ORDER BY uk.Keyword_ID SEPARATOR ', ') keyskills 
                        from e_pj_keywords uk
                        where a.Job_ID = uk.Job_ID
                ) as Keyword_Name,
                GROUP_CONCAT(DISTINCT cc.salary_description ORDER BY cc.salary_ID SEPARATOR ', ') Min_salary, 
                GROUP_CONCAT(DISTINCT dd.salary_description ORDER BY dd.salary_ID SEPARATOR ', ') Max_salary
                from post_jobs a
                INNER JOIN user_salary cc ON FIND_IN_SET(cc.salary_ID, a.Min_salary) 
                INNER JOIN user_salary dd ON FIND_IN_SET(dd.salary_ID, a.Max_salary)
                group by a.Job_id 
        ) aa
WHERE Designation LIKE '%op%' or company_name LIKE '%op%' 
And max_exp <= 15 
And Max_salary<=120 
and Ind_ID IN (10001,10002,10004,10003)
And FA_ID IN(1001,1002,1003)
group by Job_id
相关问题