mysql 自定义函数
#获取job的时间详情
DROP FUNCTION IF EXISTS `get_job_actual_work_time`;
DELIMITER $$
CREATE FUNCTION `get_job_actual_work_time`(
in_job_id char(50),
in_action char(50)
) RETURNS INT(10)
BEGIN
DECLARE out_times INT(10) DEFAULT 0;
DECLARE in_job_id_2 char(50);
DECLARE in_action_2 char(50);
SET in_job_id_2 = CONCAT('"', in_job_id, '"');
SET in_action_2 = CONCAT('"', in_action, '"');
SELECT sum((case when end_time > 0 then end_time else unix_timestamp(now()) end) - start_time) AS job_times INTO out_times
FROM t_worker_timeline WHERE job_id COLLATE=utf8mb4_unicode_ci=in_job_id_2 AND action COLLATE=utf8mb4_unicode_ci=in_action_2 AND status=1 GROUP BY job_id;
RETURN (out_times);
END;
$$
DELIMITER ;
快,滋醒这个做梦的人,有糖尿病的往后靠靠哈,不要给他点甜头!