[업무 지식]/MySQL

[LIKE] Patients With a Condition

에디터 윤슬 2024. 11. 14. 09:35

링크

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

문제

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.

The result format is in the following example.

정답

select *
from patients
where conditions like "DIAB1%"
or conditions like "% DIAB1%"

 

오답

select *
from patients
where conditions like "DIAB1%"
or conditions like "%_DIAB1%"

해설

  • like: _가 있는 경우 문자가 있으면 추출
  • like: ' '(공백)이 있는 경우 공백을 넣어야 인식