1) ๋ฌธ์ ์ค๋ช
- ๋ค์์ ํ์ ์ ๋ณด๋ฅผ ๋ด์ PATIENT ํ ์ด๋ธ๊ณผ ์์ฌ ์ ๋ณด๋ฅผ ๋ด์ DOCTOR ํ ์ด๋ธ, ๊ทธ๋ฆฌ๊ณ ์ง๋ฃ ์์ฝ๋ชฉ๋ก์ ๋ด์ APPOINTMENT์ ๋ํ ํ ์ด๋ธ์ ๋๋ค.
- PATIENT ํ ์ด๋ธ์ ๋ค์๊ณผ ๊ฐ์ผ๋ฉฐ PT_NO, PT_NAME, GEND_CD, AGE, TLNO๋ ๊ฐ๊ฐ ํ์๋ฒํธ, ํ์์ด๋ฆ, ์ฑ๋ณ์ฝ๋, ๋์ด, ์ ํ๋ฒํธ๋ฅผ ์๋ฏธํฉ๋๋ค.
Column name | Type | Nullable |
PT_NO | VARCHAR(N) | FALSE |
PT_NAME | VARCHAR(N) | FALSE |
GEND_CD | VARCHAR(N) | FALSE |
AGE | INTEGER | FALSE |
TLNO | VARCHAR(N) | TRUE |
- DOCTOR ํ ์ด๋ธ์ ๋ค์๊ณผ ๊ฐ์ผ๋ฉฐ DR_NAME, DR_ID, LCNS_NO, HIRE_YMD, MCDP_CD, TLNO๋ ๊ฐ๊ฐ ์์ฌ์ด๋ฆ, ์์ฌID, ๋ฉดํ๋ฒํธ, ๊ณ ์ฉ์ผ์, ์ง๋ฃ๊ณผ์ฝ๋, ์ ํ๋ฒํธ๋ฅผ ๋ํ๋ ๋๋ค.
Column name | Type | Nullable |
DR_NAME | VARCHAR(N) | FALSE |
DR_ID | VARCHAR(N) | FALSE |
LCNS_NO | VARCHAR(N) | FALSE |
HIRE_YMD | DATE | FALSE |
MCDP_CD | VARCHAR(N) | TRUE |
TLNO | VARCHAR(N) | TRUE |
- APPOINTMENT ํ ์ด๋ธ์ ๋ค์๊ณผ ๊ฐ์ผ๋ฉฐ APNT_YMD, APNT_NO, PT_NO, MCDP_CD, MDDR_ID, APNT_CNCL_YN, APNT_CNCL_YMD๋ ๊ฐ๊ฐ ์ง๋ฃ ์์ฝ์ผ์, ์ง๋ฃ์์ฝ๋ฒํธ, ํ์๋ฒํธ, ์ง๋ฃ๊ณผ์ฝ๋, ์์ฌID, ์์ฝ์ทจ์์ฌ๋ถ, ์์ฝ์ทจ์๋ ์ง๋ฅผ ๋ํ๋ ๋๋ค.
Column name | Type | Nullable |
APNT_YMD | TIMESTAMP | FALSE |
APNT_NO | INTEGER | FALSE |
PT_NO | VARCHAR(N) | FALSE |
MCDP_CD | VARCHAR(N) | FALSE |
MDDR_ID | VARCHAR(N) | FALSE |
APNT_CNCL_YN | VARCHAR(N) | TRUE |
APNT_CNCL_YMD | DATE | TRUE |
2) ๋ฌธ์
- PATIENT, DOCTOR ๊ทธ๋ฆฌ๊ณ APPOINTMENT ํ ์ด๋ธ์์ 2022๋ 4์ 13์ผ ์ทจ์๋์ง ์์ ํ๋ถ์ธ๊ณผ(CS) ์ง๋ฃ ์์ฝ ๋ด์ญ์ ์กฐํํ๋ SQL๋ฌธ์ ์์ฑํด์ฃผ์ธ์.
- ์ง๋ฃ์์ฝ๋ฒํธ, ํ์์ด๋ฆ, ํ์๋ฒํธ, ์ง๋ฃ๊ณผ์ฝ๋, ์์ฌ์ด๋ฆ, ์ง๋ฃ์์ฝ์ผ์ ํญ๋ชฉ์ด ์ถ๋ ฅ๋๋๋ก ์์ฑํด์ฃผ์ธ์.
- ๊ฒฐ๊ณผ๋ ์ง๋ฃ์์ฝ์ผ์๋ฅผ ๊ธฐ์ค์ผ๋ก ์ค๋ฆ์ฐจ์ ์ ๋ ฌํด์ฃผ์ธ์.
3) ์์
- PATIENT ํ ์ด๋ธ์ด ๋ค์๊ณผ ๊ฐ๊ณ ,
PT_NO | PT_NAME | GEND_CD | AGE | TLNO |
PT22000019 | ๋ฐ๋ผ | W | 10 | 01079068799 |
PT22000043 | ์ค์ค์๋ | M | 68 | 01031294124 |
PT22000052 | ์ ๋ | W | 60 | NULL |
PT22000071 | ๋ชฌ๋ชฌ | M | 31 | 01076489209 |
PT22000097 | ์๊ฐ | M | 19 | NULL |
- DOCTOR ํ ์ด๋ธ์ด ๋ค์๊ณผ ๊ฐ๊ณ ,
DR_NAME | DR_ID | LCNS_NO | HIRE_YMD | MCDP_CD | TLNO |
๋ฃจํผ | DR20090029 | LC00010001 | 2009-03-01 | CS | 01085482011 |
๋๋ชจ | DR20200012 | LC00911162 | 2020-03-01 | CS | 01089483921 |
ํํฌํ | DR20140011 | LC00082201 | 2014-03-01 | NP | 01098428957 |
์ ค๋ผ๋น | DR20160031 | LC00340327 | 2016-11-01 | OB | 01023981922 |
ํ ๋ฆฌ | DR20190129 | LC00099911 | 2019-03-01 | NS | 01058390758 |
- APPOINTMENT ํ ์ด๋ธ์ด ๋ค์๊ณผ ๊ฐ์ ๋,
APNT_YMD | APNT_NO | PT_NO | MCDP_CD | MDDR_ID | APNT_CNCL_YN | APNT_CNCL_YMD |
2022-04-13 12:30:00.000000 | 42 | PT22000071 | CS | DR20090029 | N | NULL |
2022-04-13 15:30:00.000000 | 43 | PT22000019 | CS | DR20200012 | N | NULL |
2022-04-13 09:00:00.000000 | 46 | PT22000043 | CS | DR20090029 | N | NULL |
2022-07-09 11:00:00.000000 | 74 | PT22000042 | NP | DR20100011 | N | NULL |
2022-12-13 12:30:00.000000 | 110 | PT22000097 | NP | DR20160011 | Y | 2022-12-03 |
- SQL์ ์คํํ๋ฉด ๋ค์๊ณผ ๊ฐ์ด ์ถ๋ ฅ๋์ด์ผ ํฉ๋๋ค.
APNT_NO | PT_NAME | PT_NO | MCDP_CD | DR_NAME | APNT_YMD |
46 | ์ค์ค์๋ | PT22000043 | CS | ๋ฃจํผ | 2022-04-13 09:00:00.000000 |
42 | ๋ชฌ๋ชฌ | PT22000071 | CS | ๋ฃจํผ | 2022-04-13 12:30:00.000000 |
43 | ๋ฐ๋ผ | PT22000019 | CS | ๋๋ชจ | 2022-04-13 15:30:00.000000 |
4) ํ์ด
SELECT APNT_NO
, (SELECT PT_NAME
FROM PATIENT p
WHERE p.PT_NO = a.PT_NO) AS "PT_NAME"
, PT_NO
, MCDP_CD
, (SELECT DR_NAME
FROM DOCTOR d
WHERE d.DR_ID = a.MDDR_ID) AS "DR_NAME"
, APNT_YMD
FROM APPOINTMENT a
WHERE MCDP_CD = 'CS'
AND DATE_FORMAT(APNT_YMD, '%Y-%m-%d') = '2022-04-13'
AND APNT_CNCL_YN = 'N'
ORDER BY APNT_YMD ASC;
[Reference]
๋ฐ์ํ