MySQL命令不在存储过程中工作

时间:2017-10-10 08:25:19

标签: mysql sql

我想订购有关员工的记录'名称和他们的checkin_date。 但结果并不像预期的那样。 我有以下存储过程:

BEGIN

SELECT 
    concat(u.firstname,' ',u.lastname) as fullname, t.date_from as checkin_date, 
    t.date_to as checkout_date, t.delayed_checkin_remarks, t.early_checkout_remarks, t.leave_remarks, t.leave_status, t.checkin_time, t.checkout_time
FROM
    users u
LEFT JOIN (
    SELECT user_id as id, DATE(leave_from) as date_from, DATE(leave_to) as date_to, 
        NULL as checkin_time, NULL as checkout_time,
        NULL as delayed_checkin_remarks, NULL as early_checkout_remarks, 
        CONCAT(' <u>LeaveType : ', (
            SELECT title 
            FROM leave_type
            WHERE id = l.leave_type_id),
            '</u><br/>', leave_description) as leave_remarks, leave_status
    FROM users_leave_request l 
    WHERE DATE(leave_from) between date(start_date) AND date(end_date) 
       OR DATE(leave_to) BETWEEN date(start_date) AND date(end_date)

    UNION ALL

    SELECT users_id as id, DATE(checkin_time) as date_from, DATE(checkout_time) as date_to, 
        TIME(checkin_time) as checkin_time, TIME(checkout_time) as checkout_time,
        delayed_checkin_remarks, early_checkout_remarks, NULL as leave_remarks, NULL as leave_status
    FROM checkin_checkout
    WHERE DATE(checkin_time) between date(start_date) AND date(end_date) 
       OR DATE(checkout_time) BETWEEN date(start_date) AND date(end_date)
    ) as t
  ON (u.id = t.id)
ORDER by fullname, checkin_date;

END

但结果并不像预期的那样:

Jack  | 2015-01-23 | 09:00:49 |
Jack  | 2015-01-30 | 09:00:49 |
Jack  | 2015-01-26 | 09:00:49 |
Jack  | 2015-01-27 | 09:00:49 |

当不在存储过程中时,我认为它正在输出所需的结果集。

0 个答案:

没有答案