Mysql收集In条件的数据

时间:2015-11-25 05:45:29

标签: php mysql laravel-5

我正在开发作业门户网站应用程序..

员工正在注册其资格。

员工成功注册后,

在两个条件下添加资格的工作。

即AND,OR case。

假设一个具有两个AND条件的资格的工作,如。

Engineering | Btech | Mechanical Engineering | regular | 80 % 
Diploma | CAD | Computer Applications | Distance | 70%
Engineering | Btech | Mechanical Engineering | regular | 80 % 
Diploma |  |   |  | 70%

在输入工作资格后,我将其收集为数组。

   $a = ["27","26"]; // dummy data
   $b = ["62"]; // dummy data
   $c = ["59"]; // dummy data

我想从符合上述条件的员工资格表中收集 EMPLOYEE ID 数据。

enter image description here

我尝试了下面的Where In查询。

SELECT * FROM `otc_employee_qualifications` 
WHERE `emp_qualifctn_type` IN ('26','27')
AND `qualification_value` IN ('59','32')
AND `emp_qualifctn_branch` IN ('156')
AND `emp_qualifctn_stream` IN ('2')
AND `qualification_mark` >= 27
GROUP BY `employee_id` 

4 个答案:

答案 0 :(得分:0)

尝试使用AND代替where加入两个条件。

SELECT * FROM `otc_employee_qualifications` 
WHERE `emp_qualifctn_type` IN ('26','27')
AND `qualification_value` IN ('59','32')
AND `emp_qualifctn_branch` IN ('156')
AND `emp_qualifctn_stream` IN ('2')
AND `qualification_mark` >= 27
GROUP BY `employee_id` 

答案 1 :(得分:0)

之后使用AND
SELECT * FROM `otc_employee_qualifications` 
WHERE `emp_qualifctn_type` IN ('26','27')
AND `qualification_value` IN ('59','32')
AND `emp_qualifctn_branch` IN ('156')
AND `emp_qualifctn_stream` IN ('2')
AND `qualification_mark` >= 27
GROUP BY `employee_id` 

答案 2 :(得分:0)

使用AND并更改条件

SELECT * FROM `otc_employee_qualifications` 
WHERE `emp_qualifctn_type` IN ('26','27')
AND `qualification_value` IN ('59','32')
AND `emp_qualifctn_branch` IN ('156')
AND `emp_qualifctn_stream` IN ('2')
AND `qualification_mark` >= 27
GROUP BY `employee_id` 

答案 3 :(得分:0)

第一次尝试AND而不是WHERE WHERE。{     SELECT * FROM otc_employee_qualifications WHERE emp_qualifctn_type IN ('26','27') AND qualification_value IN ('59','32') AND emp_qualifctn_branch IN ('156') AND emp_qualifctn_stream IN ('2') AND qualification_mark >= 27 GROUP BY employee_id