Coding Planet

leetcode > 1527. Patients With a Condition ๋ณธ๋ฌธ

SQL

leetcode > 1527. Patients With a Condition

jhj.sharon 2023. 2. 6. 19:43
๋ฐ˜์‘ํ˜•

โœจ ๋ฌธ์ œ: 1527. Patients With a Condition

https://leetcode.com/problems/patients-with-a-condition/solutions/?q=regexp+oracle&orderBy=most_relevant

๐Ÿ’ป์ฝ”๋“œ

select patient_id,
       patient_name,
       conditions
from   patients
where  regexp_like(conditions, '^DIAB1| DIAB1')

 

๐Ÿ‘ฉ‍๐Ÿ’ป ํ’€์ด ๋ฐฉ๋ฒ•

  • ์ด๋ฒˆ ๋ฌธ์ œ์˜ ๊ฒฝ์šฐ condition like = '%DIAB1' OR condition LIKE = '% DIABL1%'์œผ๋กœ ๊ฐ„๋‹จํžˆ ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์ด๋‹ค.
  • ๊ทธ๋Ÿฌ๋‚˜ ํ•จ์ •์ด ํ•˜๋‚˜์žˆ๋Š”๋ฐ ๊ณต๋ฐฑ(SPACE)์ด ๊ตฌ๋ถ„์ž๋กœ ์“ฐ์ธ๋‹ค๋Š” ๊ฒƒ์„ ์ฃผ์˜ํ•ด์•ผํ•œ๋‹ค. 
  • ํ•˜์ง€๋งŒ LIKE์™€ IN์„ ๊ฐ™์ด ์“ฐ์ง€ ๋ชปํ•ด ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•œ ํ•จ์ˆ˜ REGEXP_LIKE๋ฅผ ์ด์šฉํ–ˆ๋‹ค.
  • REGEXP_LIKE(์ปฌ๋Ÿผ๋ช…, ์ •๊ทœํ‘œํ˜„์‹) - ^: ์ฒซ๊ธ€์ž๋กœ ์‹œ์ž‘, | = ๋˜๋Š”( OR)

 

 


๐Ÿ”” ๋Š๋‚€์ 

  • ์ •๊ทœํ‘œํ˜„์‹์ด ์ต์ˆ™ํ•˜์ง€ ์•Š๋‹ค. ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ์•„์ง ๊ณต๋ถ€ ์•ˆํ•ด์„œ....
  • REGEXP์€ ์ •๊ทœํ‘œํ˜„์‹(REGULAR EXPRESSION)์˜ ์•ฝ์ž์ด๋‹ค. ์ •๊ทœํ‘œํ˜„์‹์€ ๋ฌธ์ž์—ด์—์„œ ํŠน์ • ๋‚ด์šฉ์„ ์ฐพ๊ฑฐ๋‚˜ ๋Œ€์ฒด ๋˜๋Š” ๋ฐœ์ทŒํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋˜๋Š” ์–ธ์–ด๊ทœ์น™์ด๋‹ค.
๋ฐ˜์‘ํ˜•

'SQL' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

leetcode > 1795. Rearrange Products Table  (0) 2023.02.07
leetcode > 1141. User Activity for the Past 30 Days I  (0) 2023.02.06
leetcode > 1484. Group Sold Products By The Date  (0) 2023.02.06
leetcode > 1667. Fix Names in a Table  (0) 2023.02.06
leetcode > 196. Delete Duplicate Emails  (0) 2023.02.06
Comments