力扣-患某种疾病的患者
大家好,我是空空star,本篇带大家了解一道简单的力扣sql练习题。
文章目录
- 前言
- 一、题目:1527. 患某种疾病的患者
- 二、解题
- 1.正确示范①
- 提交SQL
- 运行结果
- 2.正确示范②
- 提交SQL
- 运行结果
- 3.正确示范③
- 提交SQL
- 运行结果
- 4.正确示范④
- 提交SQL
- 运行结果
- 5.其他
- 总结
前言
一、题目: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 。
按 任意顺序 返回结果表。
查询结果格式如下示例所示。
输入:
Patients表:
+------------+--------------+--------------+
| patient_id | patient_name | conditions |
+------------+--------------+--------------+
| 1 | Daniel | YFEV COUGH |
| 2 | Alice | |
| 3 | Bob | DIAB100 MYOP |
| 4 | George | ACNE DIAB100 |
| 5 | Alain | DIAB201 |
+------------+--------------+--------------+
输出:
+------------+--------------+--------------+
| patient_id | patient_name | conditions |
+------------+--------------+--------------+
| 3 | Bob | DIAB100 MYOP |
| 4 | George | ACNE DIAB100 |
+------------+--------------+--------------+
解释:Bob 和 George 都患有代码以 DIAB1 开头的疾病。
二、解题
1.正确示范①
提交SQL
select patient_id,patient_name,conditions
from Patients
where conditions like 'DIAB1%'
or conditions like '% DIAB1%';
运行结果
2.正确示范②
提交SQL
select patient_id,patient_name,conditions
from Patients
where conditions REGEXP '^DIAB1|\\sDIAB1';
运行结果
3.正确示范③
提交SQL
select patient_id,patient_name,conditions
from Patients
where conditions rlike '^DIAB1|\\sDIAB1';
运行结果
4.正确示范④
提交SQL
select patient_id,patient_name,conditions
from Patients
where conditions like 'DIAB1%'
union
select patient_id,patient_name,conditions
from Patients
where conditions like '% DIAB1%';
运行结果
5.其他
总结
正确示范①思路:
like
+or
+like
正确示范②思路:
REGEXP
正确示范③思路:
rlike
正确示范④思路:
like
+union
+like
力扣-患某种疾病的患者相关推荐
- 1527. 患某种疾病的患者
1527. 患某种疾病的患者 前言 like 前言 患某种疾病的患者 患者信息表: Patients +--------------+---------+ | Column Name | Type | ...
- 1527. 患某种疾病的患者(like关键字的使用)
1527. 患某种疾病的患者 患者信息表: Patients 写一条 SQL 语句,查询患有 I 类糖尿病的患者 ID (patient_id).患者姓名(patient_name)以及其患有的所有疾 ...
- SQL入门:第三天 -->leetCode1527:患某种疾病的患者
文章目录 题目描述 解题步骤 总结 题目描述 原题链接:1527. 患某种疾病的患者 患者信息表: Patients +--------------+---------+ | Column Name ...
- Leetcode-SQL学习计划-SQL入门-1527.患某种疾病的患者【regexp正则表达式匹配】
链接:https://leetcode.cn/problems/patients-with-a-condition/ -- 1527.患某种疾病的患者 -- 链接:https://leetcode.c ...
- 1527.患某种疾病的患者
文章目录 1.题目 2.示例 3.答案 1.题目 表: Employees ±------------±--------+ | Column Name | Type | ±------------±- ...
- Mysql 查询患某种疾病的患者
题目 患者信息表: Patients+--------------+---------+ | Column Name | Type | +--------------+---------+ | pat ...
- 每一题-101(患某种疾病的患者)
题101: 根据下表写一条 SQL 语句,查询患有 I 类糖尿病的患者 ID (patient_id).患者姓名(patient_name)以及其患有的所有疾病代码(conditions).I 类糖尿 ...
- 【LeetCode-SQL】1527. 患某种疾病的患者
目录 一.题目 二.解决 1.or 2.正则表达式 三.参考 一.题目 患者信息表: Patients +--------------+---------+ | Column Name | Type ...
- 1527. 患某种疾病的患者(SQL)
题目:https://leetcode-cn.com/problems/patients-with-a-condition/ 患者信息表: Patients +--------------+----- ...
最新文章
- CPU 的一些基本知识总结
- 信息学奥赛一本通(C++)在线评测系统——基础(一)C++语言—— 1039:判断数正负
- SpringMvc @RequestParam、 @RequestBody、@RequestPart 的区别
- 华为ensp命令大全_电脑网络:华为交换机基础知识及基本命令配置大全,新手的福音...
- 字典中文乱码怎么处理_CATIA教程技巧和二次开发宏:我的零件有很多的几何体,但是几何体的名称是乱的,还有乱码,影响我的后续操作,我该怎么处理?...
- CSS3和js炫酷点击按钮3D翻转动画特效
- unix环境高级编程(第三版)-读书笔记1
- windows 微信多开脚本
- 推荐个不错的 Word 全文翻译和压缩工具!
- led灯光衰怎么解决_影响LED灯具光衰的原因及解决方法
- paip 破解网站手机验证码
- oracle异常策略,oracle segmentation fault错误
- python 声音强度检测_python检测音频中的静音
- 如何在Linux系统下的IntelliJ IDEA 2018.3.5下载与安装以及激活教程
- Java与PHP之争
- mysql之自定义函数
- git解决拉取代码本地代码未提交
- python海龟绘图实例教程-python海龟turtle绘图实例教程
- 西北师大与新华三开展物联网战略合作,共建“物联网联合实验室”
- dolphinscheduler_sql_调用时间参数