SELECT R.member_id ,R.ANSWER_TIMES ,Q.question_no ,Q.question_name ,(CASE WHEN Q.control_id in (0,1,2) and --A.free_text_flg is null COALESCE(A.free_text_flg,0) = 0 THEN A.answer ELSE R.answer END) AS answer ,to_char(R.insert_date , 'yyyy/MM/dd HH24:MI:SS') AS insert_date from t_reply R INNER JOIN m_answer A ON R.enquete_id = A.enquete_id AND R.question_id = A.question_id AND A.DEL_FLG =0 INNER JOIN m_question Q ON R.enquete_id = A.enquete_id AND R.question_id = A.question_id AND R.answer_id = A.answer_id AND R.question_no = Q.question_no AND Q.DEL_FLG = 0 WHERE Q.enquete_id = /*enquete_id*/ AND R.enquete_id = /*enquete_id*/ and R.member_id between /*minMemberId*/ and /*maxMemberId*/ and R.member_id is not null ORDER BY R.member_id,Q.question_no,A.answer_id