Sql的字符串匹配 like

[1527. 患某种疾病的患者]1527. 患某种疾病的患者

患者信息表: Patients

+--------------+---------+
| Column Name  | Type    |
+--------------+---------+
| patient_id   | int     |
| patient_name | varchar |
| conditions   | varchar |
+--------------+---------+
patient_id (患者 ID)是该表的主键。
'conditions' (疾病)包含 0 个或以上的疾病代码,以空格分隔。
这个表包含医院中患者的信息。
 

写一条 SQL 语句,查询患有 I 类糖尿病的患者 ID (patient_id)、患者姓名(patient_name)以及其患有的所有疾病代码(conditions)。I 类糖尿病的代码总是包含前缀 DIAB1 。

按 任意顺序 返回结果表。
来源:力扣(LeetCode)
select patient_id,patient_name,conditions
from Patients
where conditions like '% DIAB1%' or conditions like 'DIAB1%';

% 匹配多个字符
"DIAB1%"是查询该类在排头的情况;

"% DIAB1%"是查询该类处在后面的情况,如果类型中的信息中存在者最后一个测试用例的情况:"XXXDIAB1.....",加上的空格可以排除

posted @ 2022-08-03 15:01  阿榴  阅读(399)  评论(0)    收藏  举报