EXISTS (
SELECT 1
FROM tcm_live_watch_record wr
WHERE wr.session_id = r.session_id
AND wr.app_user_id = r.app_user_id
)
r.id,
r.live_course_id AS courseId,
r.session_id AS sessionId,
r.app_user_id AS userId,
u.nickname AS userNickname,
u.phone AS userPhone,
u.avatar AS userAvatar,
c.title AS courseTitle,
NULL AS categoryName,
s.start_time AS startTime,
s.live_status AS liveStatus,
r.reserve_time AS reserveTime,
r.is_cancel AS isCancel,
CASE WHEN THEN 1 ELSE 0 END AS hasWatched
FROM tcm_live_reserve r
INNER JOIN tcm_live_course c ON c.id = r.live_course_id AND c.deleted = 0
INNER JOIN tcm_live_session s ON s.id = r.session_id AND s.deleted = 0
LEFT JOIN tcm_app_user u ON u.id = r.app_user_id AND u.deleted = 0
WHERE r.is_cancel = 0
AND r.live_course_id = #{courseId}
AND r.session_id = #{sessionId}
AND u.phone LIKE CONCAT('%', #{phone}, '%')
AND c.title LIKE CONCAT('%', #{courseName}, '%')
AND s.live_status = #{liveStatus}
AND
AND NOT
AND r.reserve_time =]]> #{reserveFrom}
AND r.reserve_time #{reserveTo}