在mysql中如何使用在where子句中分隔的camma传递多个值

时间:2017-10-27 05:21:02

标签: mysql

select log_id as attendanceId,l.user_id as employeeId,l.log_date as attnInDate,emp.emp_name as 
employeeName,l.in_remarks as inRemarks,emp.dept_id as departmentId,fn_get_hr_dept_name(emp.dept_id) as 
departmentName, l.out_remarks as outRemarks,group_concat(CASE WHEN log_date = log_date THEN log_time ELSE '' END) AS logTimings,MIN(CASE WHEN log_date = log_date THEN log_time ELSE NULL END) inTime1,MAX(CASE WHEN log_date = log_date THEN log_time ELSE NULL END) inTime2,MAX(CASE WHEN log_date = log_date THEN log_time ELSE NULL END) outTime1,TIME_FORMAT(timediff(MAX(CASE WHEN log_date = log_date THEN log_time ELSE NULL END),MIN(CASE WHEN log_date = log_date THEN log_time ELSE NULL END)), '%H:%i') as workingHrsMonth

 from at_hr_logs_2017_October l,at_hr_emp emp where log_date=curdate() 
and l.user_id=emp.emp_code and emp.dept_id=5 and 6 group by user_id;

想像dept_id = 5,6,7,8那样传递dept值

有关此问题的任何解决方案请告诉我。

3 个答案:

答案 0 :(得分:0)

我假设您在 where 子句中谈论emp.dept_id = 5 and 6, 你将不得不使用' IN'在这种情况下。

Ex:emp.dept_id IN(5,6,7,8)

答案 1 :(得分:0)

正如Andreas Feste所说,你可以使用IN运算符。

使用

 where dept_id in (5,6,7,8)

答案 2 :(得分:0)

这可能对您有所帮助

SELECT column1
FROM tablename          
WHERE column IN (val1, val2, val3);