当前位置:网站首页>Mysql---三张表(student,课程,分数) 查询课程为数学的学生姓名,编号,成绩
Mysql---三张表(student,课程,分数) 查询课程为数学的学生姓名,编号,成绩
2022-06-24 06:41:00 【晚风吹儿】
一、设计表
1.student表

2.subject表

3.score表

二、查询数据
需求:查询课程为数学的学生姓名,编号,成绩
方法一:
where语句查询
select student.sno,student.sname,score.score from student,subject,score where student.sno = score.sno and subject.cno = score.cno and subject.subject_name="数学";
查询结果:
方法二:
使用内连接
select 表1.字段,表2.字段,表3.字段 from 表1 inner join 表2 on 表1.字段= 表2.字段 inner join 表3 on 表1.字段=表3.字段 where 条件;
select s.sno,s.sname,c.score from student s inner join score c on s.sno=c.sno inner join subject u on c.cno=u.cno where u.subject_name="数学"

解析:
1、分别查看三个表,找到有关联的字段
2、看表可以看出,student表的sno与subject表的sno可匹配,subject表的与score表的cno匹配,所以可以通过这两个字段筛选数据
3、再加个指定科目:数学,即可把对应数据找到
边栏推荐
- setInterval里面的函数不能有括号
- 【pointNet】基于pointNet的三维点云目标分类识别matlab仿真
- 内网学习笔记(4)
- In the middle of the year, I have prepared a small number of automated interview questions. Welcome to the self-test
- Spark累加器和广播变量
- 0 foundation a literature club low code development member management applet (4)
- 为什么要用lock 【readonly】object?为什么不要lock(this)?
- Mysql开启BINLOG
- Are internal consultants and external consultants in SAP implementation projects difficult or successful? [English version]
- Virtual file system
猜你喜欢
随机推荐
【均衡器】LS均衡器,DEF均衡器以及LMMSE均衡器的误码率性能对比仿真
JVM debugging tool -jstack
多传感器融合track fusion
华为云数据库进阶学习
Coding helps promote the internationalization of Tencent games
JVM调试工具-Arthas
Are internal consultants and external consultants in SAP implementation projects difficult or successful? [English version]
[problem solving] virtual machine configuration static IP
[security] how to [host security - hybrid cloud version] support secure access to non Tencent virtual machines
Computing power and intelligence of robot fog
Typora收费?搭建VS Code MarkDown写作环境
Typora charges? Build vs Code markdown writing environment
Outils de débogage JVM - Arthas
FreeRTOS MPU使系统更健壮!
Canal安装配置
c#:互斥锁的使用
0 foundation a literature club low code development member management applet (5)
蓝牙耳机怎么连接电脑使用,win10电脑如何连接蓝牙耳机
Why use lock [readonly] object? Why not lock (this)?
What is the role of domain name websites? How to query domain name websites









