这是查询
SET @row_number = 0;
SET @emp_id = NULL;
SELECT
t.User_ID,concat(employee_profile.fname,' ',employee_profile.mname,' ',employee_profile.lname) as fullname,
MAX(CASE WHEN Verify_State = '0' THEN Verify_Date END) AS time_in,
MAX(CASE WHEN Verify_State = '1' THEN Verify_Date END) AS time_out,
timeshift.time_in as shiftstart, timeshift.time_ou as shiftend,timeshift_day.day_id,MAX(CASE WHEN Verify_State = '0' THEN Work_time END)
FROM( SELECT *,
@row_number:=CASE WHEN @emp_id = User_ID THEN @row_number + 1 ELSE 0 END AS rn,
TRUNCATE(@row_number / 2, 0) AS rn_grp,
@emp_id:= User_ID
FROM attendance_table ORDER BY User_ID, Verify_Date) t
left Join employee_profile ON employee_profile.emp_id_no = t.User_ID
left JOIN employee_timeshift ON employee_timeshift.emp_id_no = t.User_ID
left JOIN timeshift on timeshift.id = employee_timeshift.timeshift_id
left JOIN timeshift_day on timeshift_day.timeshift_id = timeshift.id and
timeshift_day.day_id =
if(max(CASE WHEN t.Verify_State = '0' THEN t.Work_time END) BETWEEN '02:00:00' and '06:00:00',(DAYOFWEEK(t.Verify_Date) -1)-1,DAYOFWEEK(t.Verify_Date)-1)
where date(Verify_Date) BETWEEN '2018-05-01' and '2018-06-18'
GROUP BY t.User_ID, t.rn_grp;
我有这个错误
[Err] 1111 - Invalid use of group function
这里的问题是使用“max(CASE WHEN t.Verify_State ='0'THEN t.Work_time END”作为if语句中的参数。