๐Ÿ’ SQL (Programmers)/String, Date

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค][SQL] ์ทจ์†Œ๋˜์ง€ ์•Š์€ ์ง„๋ฃŒ ์˜ˆ์•ฝ ์กฐํšŒํ•˜๊ธฐ

์„ ๋‹ฌ 2023. 6. 21. 23:27
๋ฐ˜์‘ํ˜•

https://school.programmers.co.kr/learn/courses/30/lessons/132204

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

 

PATIENTDOCTOR ๊ทธ๋ฆฌ๊ณ  APPOINTMENT ํ…Œ์ด๋ธ”์—์„œ

2022๋…„ 4์›” 13์ผ ์ทจ์†Œ๋˜์ง€ ์•Š์€ ํ‰๋ถ€์™ธ๊ณผ(CS)

์ง„๋ฃŒ ์˜ˆ์•ฝ ๋‚ด์—ญ์„ ์กฐํšŒํ•˜๋Š” SQL๋ฌธ์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.

์ง„๋ฃŒ์˜ˆ์•ฝ๋ฒˆํ˜ธ, ํ™˜์ž์ด๋ฆ„, ํ™˜์ž๋ฒˆํ˜ธ, ์ง„๋ฃŒ๊ณผ์ฝ”๋“œ, ์˜์‚ฌ์ด๋ฆ„, ์ง„๋ฃŒ์˜ˆ์•ฝ์ผ์‹œ ํ•ญ๋ชฉ์ด ์ถœ๋ ฅ๋˜๋„๋ก ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.

๊ฒฐ๊ณผ๋Š” ์ง„๋ฃŒ์˜ˆ์•ฝ์ผ์‹œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•ด์ฃผ์„ธ์š”.

 

-- ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”
select ad.apnt_no, p.pt_name, p.pt_no, ad.mcdp_cd, ad.dr_name, ad.apnt_ymd
from patient p join
    (SELECT apnt_no, pt_no, dr_name, apnt_ymd, a.mcdp_cd
    from appointment a join doctor d on a.mddr_id = d.dr_id
    where a.apnt_cncl_yn="N" and date_format(apnt_ymd, "%Y%m%d")='20220413' and a.mcdp_cd="CS") ad on p.pt_no = ad.pt_no
order by ad.apnt_ymd asc

 

appointment ์™€ doctor ํ…Œ์ด๋ธ”์„ ์กฐ์ธํ•˜๊ณ , ๊ทธ ํ›„ ๊ทธ ํ…Œ์ด๋ธ”์„ patient ํ…Œ์ด๋ธ”๊ณผ ์กฐ์ธํ–ˆ๋‹ค.

์‚ด์ง ๋งˆ์Œ์—๋Š” ์•ˆ๋“ค์ง€๋งŒ.. ํ˜„์žฌ ์ƒ๊ฐํ•˜๋Š” ๋ฐฉ๋ฒ•์ค‘ ์ตœ์„ ์ธ๋“ฏํ•˜๋‹ค.

๋ฐ˜์‘ํ˜•