求帮忙,没咋写过3表查询

火`光 2019-10-12 12:23:10
3表查询没写过,不咋会。
...全文
108 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
火`光 2019-10-18
  • 打赏
  • 举报
回复
select count(*) from
student s join course_selection c on s.sno=c.sno left join course co on c.cno=co.cno
where co.name='大学物理' and co.name='大学语文';
name不能重复赋值 但是好像没有替换and的了 应该是用子查询写。但是我想了半天一片白,是要用多表查询套子查询么
火`光 2019-10-18
  • 打赏
  • 举报
回复
我就试了那个同时大学物理和大学语文的我的sql语句跟你的查询结果一样都是0不对
火`光 2019-10-18
  • 打赏
  • 举报
回复
我就试了那个同时大学物理和大学语文的我的sql语句跟你的查询结果一样都是0不对
  • 打赏
  • 举报
回复 1
设计这个题目的人,估计库表设计规范都不太了解,外键都不设置。 下次问这种问题,麻烦贴一下创建库表的SQL语句!!! 如下,勉强实现了下 1、三张表class、student、score (1)查询学生SID="1"的成绩级别? select a.SID,a.Name,a.score from test.student a where a.SID = '1' and EXISTS (select 1 from test.score b where a.score BETWEEN b.minScore and b.maxScore); (2)统计各个班中,成绩级别为优的学生人数? select count(*) from test.student a inner join test.class b on a.classID = b.classID AND EXISTS (select 1 from test.score c where a.score BETWEEN c.minScore and c.maxScore and level = '优'); 2、三张表student、course、course_selection (1)查询没有选择课程名为“大学物理”的所有学生信息? select a.*,b.*,c.* from test.student a inner join test.course_selection b on a.sno = b.sno inner join test.course c on c.cno = b.cno and c.Name != '大学物理'; (2)统计同时学习“大学物理”与“大学语文”的学生人数? select * from test.student x where x.sno in( select DISTINCT a.sno cname from test.student a inner join test.course_selection b on a.sno = b.sno inner join test.course c on c.cno = b.cno AND c.name = '大学语文' ) AND x.sno in( select DISTINCT a.sno from test.student a inner join test.course_selection b on a.sno = b.sno inner join test.course c on c.cno = b.cno AND c.name = '大学物理' );
火`光 2019-10-14
  • 打赏
  • 举报
回复
你看第3歌表,跟前面两个表都没关系。应该不是关联查询,是不是出错了,第二题还可以
蜕变之痛 2019-10-13
  • 打赏
  • 举报
回复 1
做关联 肯定有共有的字段,不然第三个表与其它2个表没啥关系
火`光 2019-10-12
  • 打赏
  • 举报
回复
问题是我不知道地3个表on谁,直接on最大成绩么
蜕变之痛 2019-10-12
  • 打赏
  • 举报
回复
A left join b on *** left join c on ***

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧