mysql 多张表公用一个序列_MYSQL多表查询

本文详细介绍了MySQL中多表查询的各种方法,包括一层嵌套子查询、普通链接、JOIN...ON、GROUP BY、HAVING等,以及如何使用正则表达式、建立索引、创建临时表和序列化操作。通过实例解析了各种查询技巧,帮助读者掌握MySQL数据库的高级查询技术。
摘要由CSDN通过智能技术生成

一、 一层嵌套子查询 --查询出来结果只有一张表

内查询结果=some()

内查询结果=any()

内查询结果 in()

1)Select 最后要查出来的结果 from 最后要查出来的结果所在表

Where 内查询结果 =(

Select 内查询结果 from 另外一张表 where 题目所给的条件(内查询条件)

);

2)当内查询结果是多个值的时候,这个时候须要用in来替换=:

Select 最后要查出来的结果 from 最后要查出来的结果所在表

Where 内查询结果in(

Select 内查询结果 from 另外一张表 where 题目所给的条件(内查询条件)

);

3)又或者是在=后面加上some或者 any;

Select 最后要查出来的结果 from 最后要查出来的结果所在表

Where 内查询结果 =some/any(

Select 内查询结果 from 另外一张表 where 题目所给的条件(内查询条件)

);

例1: select sname from student

where sno=(select sno from course where cname=‘yuwen’and cpoint>90);

例2:select sname from student where sno =(select sno from course where cpoint >90) or (select sno from student where sage >23);mysql

二、普通链接 --查询出来结果是两张表

Select * from 表1,表2 where 表1.A=表2.A and 题目里面所给的条件;

(* 表明题目最后查询的结果,两个表的链接属性)

例1:select s.sname,c.sno from student s,course.c

where s.sno=c.sno and c.cname=’yuwen’ and c.cpoint>90;

例2: select s.sname,c.sno from student.s,course.c

where s.sno=c.sno and c. cpoint >90 or s.age>23;

三、链接语句 ----join…on

select * from 表1 join 表2 on 表1.A=表2.A where (咱们题目给出的条件)你的条件 and 你的另一个条件;

select * from student join course on student.sno=course.sno where

course.cname=’shuxue’ and course.cpoint>80;正则表达式

三、聚合函数

1)AVG() –返回指定列的平均值

2) COUNT() --返回指定列中非null值的个数

3) MIN() --返回指定列

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值