SELECT
a.emp_id
, s.name
, s.department
,sum( case when TIMESTAMPDIFF(hour, min(a.punchtime), max(a.punchtime))< 4 then 1 else 0 end ) as 'Half Day'
FROM time_dimension c
LEFT JOIN machinedata a ON c.db_date = a.punchdate
LEFT JOIN emp s ON a.emp_id = s.emp_id
WHERE month(c.db_date) = 11
GROUP BY
a.emp_id
, s.name
, s.department
ORDER BY `s`.`department` ASC, s.name asc
我得到#1111 - 如果我使用上面的代码,则无效使用组功能。但是如果我在总和情况下删除min和max,则代码会运行,但会给出错误的总和。
如何在Sum Case中使用Min和Max?