Snoopy [리트코드/SQL] 10. Patients With a Condition (1527)
코딩테스트/리트코드 SQL

[리트코드/SQL] 10. Patients With a Condition (1527)

Sooyoon Jeong 2022. 12. 8.

🤔 문제 분석

1) Write an SQL query to report the patient_id, patient_name and conditions of the patients

2) who have Type I Diabetes.

3) Type I Diabetes always starts with DIAB1 prefix.

4) Return the result table in any order.

 

💡 풀이

SELECT *
FROM Patients
WHERE conditions LIKE "DIAB1%" OR conditions LIKE "% DIAB1%"

 

✍️ check point

접두사만 발라내는 것이 핵심이다.

(%DIABI%를 하면 SBDIABI 등도 출력이 된다.)

 

접두사니까 단어의 첫 글자여야 한다.

DIABI%를 쓰거나, 두번째 이상의 단어일 경우에는 무조건 " "임을 고려하여 "% DIABI%"을 사용

 

참고: 와일드카드 _는 무슨 글자인지는 모르겠으나 1개의 글자가 있는 경우 -> 이렇게 하면 SBDIABI 등도 출력됨

댓글