0
点赞
收藏
分享

微信扫一扫

MySQL数据库学习day03

小铺有酒一两不够 2022-02-02 阅读 83

day03

一、子查询

在一个select语句中嵌入了另外一个select语句,那么被嵌入的select语句叫做子查询语句。

主查询:是主要查询的对象,第一条select语句

主查询和子查询的关系:

  1. 子查询是嵌入到主查询当中的
  2. 子查询是辅助主查询的,要么充当条件,要么充当数据源
  3. 子查询是可以独立存在的语句,是一条完整的select语句

子查询的分类:

1、标量子查询:子查询返回的结果是一个数据(一行一列)

select * from students where age>(select avg(age) from students);

2、列级子查询: 子查询返回的结果是1列

select score from students as stu inner join scores as sc on stu.studentsNo=sc.studentsNo where stu.age=18;

3、行级子查询  :子查询的返回结果是一行多列

select * from students where age=(select max(age) from students);

4、表级子查询: 子查询的结果返回多行多列

select c.name,sc.score from courses as c inner join scores as sc on c.courseNo=sc.courseNo where c.name in ('数据库','操作系统','计算机网络');

二、使用正则表达式进行匹配

正则表达式是用来匹配文本当中特殊的串\字符集合。

在MySQL当中用where 加上指定的正则表达式,可以对数据进行过滤。

通过REGEXP指明正则表达式的匹配模式

select * from students where card regexp '1999';

select * from students where card regexp '199.'(.表示任意一个字符)

select * from students where card regexp '1999|1998'(|表示或,即1999或1998)

select * from students where card regexp '199[0123456]'([]括号内的表示其中任意一位即可)

举报

相关推荐

mysql学习day03

day03

Day03

JS学习打卡Day03

I LOVE MYSQL day03

Day03(

Linux Day03

0 条评论