
    SELECT 
        user_details.user_id AS user_id,
        ifnull(RepToDay,0) RepToDay, RepToDay1, RepToDay3,RepToDay2,avgToDay,noAnswerToDay,AnswerToDay, AnswerToDay - ifnull(RepToDay,0) as inRepToDay
    FROM
        (select '{user_id}' as user_id) user_details
        LEFT JOIN (SELECT 
            user_id AS user_id,
                count(distinct card_id) AS RepToDay,
                sum(case when grade = 1 then 1 else 0 end) AS RepToDay1,
                sum(case when grade = 2 then 1 else 0 end) AS RepToDay2,
                sum(case when grade = 3 then 1 else 0 end) AS RepToDay3,
                avg(grade) AS avgToDay
        FROM
            (select date,user_id, card_id, min(grade) grade from replog_data  WHERE
          date = CAST((NOW() + INTERVAL -(5) HOUR) AS DATE) and user_id = '{user_id}' and type = 2 and grade < 4 group by date, user_id, card_id ) dis_replog group by user_id
        ) user_repsToDay ON user_details.user_id = user_repsToDay.user_id
         LEFT JOIN (SELECT 
            cards_data_base.user_id AS user_id,
                ifnull(sum(repetition),0) noAnswerToDay,
                ifnull(sum(case when last_timing  = CAST((NOW() + INTERVAL -(5) HOUR) AS DATE) then 1 else 0 end),0) AnswerToDay
        FROM
            cards_data_base
        WHERE
            (user_id = '{user_id}')
        GROUP BY cards_data_base.user_id) user_AnswerToDay ON user_details.user_id = user_AnswerToDay.user_id
