Growth ๐ŸŒณ/Practice ๐Ÿ’ป

[Leet Code] 1527. Patients With a Condition

์ธ” 2023. 10. 30. 17:30

๐Ÿ“ข ๋ณธ ํฌ์ŠคํŒ…์— ํ™œ์šฉ๋˜๋Š” ๊ธฐ๋ณธ ๋ฌธ์ œ ๋ฐ ์ž๋ฃŒ ์ถœ์ฒ˜๋Š”

       ๋ฆฌํŠธ์ฝ”๋“œ Problems, https://leetcode.com/problemset/all/์ž„์„ ๋ฐํž™๋‹ˆ๋‹ค.


โœ” ๋ฌธ์ œ

https://leetcode.com/problems/patients-with-a-condition/description/

 

Patients With a Condition - LeetCode

Can you solve this real interview question? Patients With a Condition - Table: Patients +--------------+---------+ | Column Name | Type | +--------------+---------+ | patient_id | int | | patient_name | varchar | | conditions | varchar | +--------------+--

leetcode.com

Table : Patients

 

Write a solution to find the patient_id, patient_name, and conditions of the patients who have Type I Diabetes. Type I Diabetes always starts with DIAB1 prefix.

Return the result table in any order.


โœ” ํ’€์ด

  ๋ฌธ์ œ ์š”๊ตฌ์‚ฌํ•ญ  

 

์ œ1ํ˜• ๋‹น๋‡จ๋ณ‘ ํ™˜์ž์˜ ํ™˜์ž ID, ํ™˜์ž ์ด๋ฆ„, ์ƒํƒœ๋ฅผ ์ฐพ์•„์•ผ ํ•œ๋‹ค.

์ œ1ํ˜• ๋‹น๋‡จ๋ณ‘์€ ํ•ญ์ƒ DIAB1 ์ ‘๋‘์‚ฌ๋กœ ์‹œ์ž‘ํ•œ๋‹ค๊ณ  ํ•œ๋‹ค.

๋‹ค๋งŒ, ์˜ˆ์‹œ Output์„ ๋ณด๋ฉด ์ ‘๋‘์‚ฌ๊ฐ€  conditions ๊ฐ’์˜ ๋„์–ด์“ฐ๊ธฐ๋ฅผ ํฌํ•จํ•œ ๋‹ค์Œ ๋‹จ์–ด์— ์ ์šฉ๋˜๋Š” conditions ๊ฐ’๋„ ์ถœ๋ ฅํ•˜๋ฏ€๋กœ

์ด ์ ์„ ์ฃผ์˜ํ•ด์•ผ ํ–ˆ๋‹ค.

๋”ฐ๋ผ์„œ conditions ์กฐ๊ฑด์„ LIKE ๋ฌธ์ž์—ด ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋‘๊ฐ€์ง€๋กœ ์„ค์ •ํ–ˆ๋‹ค.

SELECT patient_id, patient_name, conditions
 FROM Patients
 WHERE conditions LIKE 'DIAB1%'
 OR conditions LIKE '% DIAB1%';

 

๐Ÿ•ต๏ธ‍โ™‚๏ธ WHERE conditions LIKE '%DIAB1%'์ด ๋ถˆ๊ฐ€๋Šฅํ•œ ์ด์œ ๋Š”

์•„๋ž˜์™€ ๊ฐ™์€ conditions ๊ฐ’์ด ์กด์žฌํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ์ด ๊ฒฝ์šฐ๋Š” DIAB1 ์ ‘๋‘์‚ฌ ์กฐ๊ฑด์„ ์ถฉ์กฑํ•˜์ง€ ๋ชปํ•œ๋‹ค.