多表查询mysql

时间:2015-03-08 08:20:13

标签: php mysql

enter image description here

我正在创建多变量& Job Portal的多表搜索查询。在创建以下长查询方面取得了一些成功,可以根据需要提供结果我需要将以上突出显示的红色圆圈分隔值(我在下面的查询中使用GROUP_CONCAT函数创建)替换为以下表格描述值。

注意: - 分隔值不在数据库字段中。我正在使用以下查询创建这些内容。

我的其他表格结构如下:

+---------------------------------------------+
   ID                     Description
+---------------------------------------------+
    1                     Delhi
    2                     Mumbai
    3                     Chennai
    4                     Kolkata
+----------------------------------------------+ 

请帮助我指导前进的方法,休息我自己做。

Select 
    a.user_id, g.username, a.mobile_no, a.location, a.DOB, a.current_CTC,     
    a.expected_CTC, a.work_exp, a.job_type, a.designation, a.Company_name,  
    a.keyskills, a.profile_headline, a.resume_path, a.Notice_period, 
    DATEDIFF(CURDATE(),Max(b.Login_date_time)) as Last_Login_days, 
    Max(b.Login_date_time) as Last_Available_on_site,

   (Select GROUP_CONCAT(DISTINCT c.Education_ID ORDER BY c.Education_ID 
   SEPARATOR ', ') user_education from user_education c where a.user_id = 
   c.User_ID) as Education_ID,

   (Select GROUP_CONCAT(DISTINCT d.FA_ID ORDER BY d.FA_ID SEPARATOR ', ') FA 
   from user_fa d where a.user_id = d.User_ID) as FA_ID,

   (Select GROUP_CONCAT(DISTINCT e.Industry_ID ORDER BY e.Industry_ID   
   SEPARATOR ', ') Industry_ID from user_industry e where a.user_id = 
   e.User_ID) as Industry_ID,

   (Select GROUP_CONCAT(DISTINCT f.Location_ID ORDER BY f.Location_ID 
   SEPARATOR ', ') Location_ID from user_preferred_locations f where 
   a.user_id = f.User_ID) as Preferred_Location_ID

   from user_details a

   left join login_history b on a.user_id = b.user_id 
   left join users g on a.user_id = g.id
   left join user_education c on a.user_id = c.User_ID
   left join user_fa d on a.user_id = d.User_ID
   left join user_industry e on a.user_id = e.User_ID
   left join user_preferred_locations f on a.user_id = f.User_ID
   INNER JOIN locations h ON FIND_IN_SET(h.location_id, f.Location_ID)
   WHERE MATCH(keyskills) AGAINST('MIS, Analysis' IN BOOLEAN MODE)
   And YEAR(CURDATE()) - YEAR(DOB)>= 18 And YEAR(CURDATE()) - YEAR(DOB)<= 45
   And work_exp >= 2 And work_exp <= 15 
   And a.current_CTC>=102 And a.current_CTC<=115 
   And a.industry IN (10001,10002,10004)
   And a.functional_area IN(1001,1002,1003) 
   And a.location_preferred IN (1,2,3,4,6,7)
   And Education_ID IN (1,5,7,8)
   And a.job_type Like '%FTP%' 
   And Notice_period >= 15
   And b.Login_date_time>=0
   And a.mobile_no is not null
   And resume_path is not null
   group by a.user_id

0 个答案:

没有答案