문제
PATIENT
, DOCTOR
그리고 APPOINTMENT
테이블에서 2022년 4월 13일 취소되지 않은 흉부외과(CS) 진료 예약 내역을 조회하는 SQL문을 작성해주세요. 진료예약번호, 환자이름, 환자번호, 진료과코드, 의사이름, 진료예약일시 항목이 출력되도록 작성해주세요. 결과는 진료예약일시를 기준으로 오름차순 정렬해주세요.
💡 조건
sql 코드
SELECT appointment.apnt_no, patient.pt_name, patient.pt_no, doctor.mcdp_cd, doctor.dr_name, appointment.apnt_ymd
FROM doctor join
(SELECT apnt_no, pt_no, mcdp_cd, mddr_id, apnt_ymd
FROM appointment
WHERE apnt_ymd like "%2022-04-13%" and apnt_cncl_yn = "N" and mcdp_cd = "CS")
as appointment on doctor.dr_id = appointment.mddr_id
JOIN patient on patient.pt_no = appointment.pt_no
ORDER BY appointment.apnt_ymd
SELECT apnt_no, pt_no, mcdp_cd, mddr_id, apnt_ymd
FROM appointment
WHERE apnt_ymd like "%2022-04-13%" and apnt_cncl_yn = "N" and mcdp_cd = "CS"
FROM doctor join
(SELECT apnt_no, pt_no, mcdp_cd, mddr_id, apnt_ymd
FROM appointment
WHERE apnt_ymd like "%2022-04-13%" and apnt_cncl_yn = "N" and mcdp_cd = "CS")
as appointment on doctor.dr_id = appointment.mddr_id
JOIN patient on patient.pt_no = appointment.pt_no
SELECT appointment.apnt_no, patient.pt_name, patient.pt_no, doctor.mcdp_cd, doctor.dr_name, appointment.apnt_ymd
ORDER BY appointment.apnt_ymd