MySQL题

1.高级字符串函数/正则表达式/子句

1. 修复表中的名字
在这里插入图片描述
编写解决方案,修复名字,使得只有第一个字符是大写的,其余都是小写的。返回按 user_id 排序的结果表。

select user_id,name from Users 
where contact(upper(substring(name,1,1)),lower(substring(name,2)))

substring(expre,addr,length),切割字符串起始位置、长度
upper()大写、lower()小写
contact(),拼接字符串

2. 患某种疾病的患者
在这里插入图片描述
查询患有 I 类糖尿病的患者 ID 、患者姓名以及其患有的所有疾病代码。I 类糖尿病的代码总是包含前缀 DIAB1 。
按 任意顺序 返回结果表。

\\s表示一个空格;^表示以它开头

> select patient_id,patient_name,conditions from Patients
>  where conditions regexp '\\sdiab1|^diab1'

词边界\\b,只能检查拉丁字符和数字a-z|A-Z|0-9。
https://blog.csdn.net/m0_52409770/article/details/123483978
正则表达式:https://blog.csdn.net/atu1111/article/details/105955377

select patient_id,patient_name,conditions from Patients
 where conditions regexp '\\bdiab1'

不用正则表达式:

select patient_id,patient_name,conditions from Patients 
where conditions like "% diab1%" or conditions like 'diab1%'

conditions前加空格,

select patient_id,patient_name,conditions from Patients 
where concat(' ',conditions) like '% diab1%'

3. 查找拥有有效邮箱的用户1517
在这里插入图片描述
一个有效的电子邮件具有前缀名称和域,其中:

  1. 前缀名称是一个字符串,可以包含字母大写或小写,数字,下划线 ‘_’ ,点 ‘.’ 和/或破折号 ‘-’ 。前缀必须以字母开头。
    2.域为 ‘@leetcode.com’ 。
    以任何顺序返回结果表。
select user_id,name,mail from Users 
where mail regexp '^[a-zA-Z]+[a-zA-Z0-9_./-]*@leetcode//.com'
@在后面的版本中可以不用转义//@
where mail regexp '^[a-zA-Z][\\w.-]*\\@leetcode\\.com$'
\w表示匹配一个字符数字下划线,直接取代[a-zA-Z0-9_]

4. 删除重复的电子邮箱196

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值