开发者社区> 问答> 正文

MySQL多表查询问题

学生表student (stu_id ,stu_name ); 课程表course (c_id,c_name);
成绩表score (stu_id ,c_id,score);
1、在学生表中添加一条数据:
2、查询名字为Tom的学生所选的课程:
3、查询stu_id为3的学生所学课程的成绩

展开
收起
蛮大人123 2016-03-18 14:10:57 3478 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪

    学生表student (stu_id ,stu_name ); 课程表course (c_id,c_name)
    成绩表score (stu_id ,c_id,score)
    1、在学生表中添加一条数据:insert into student (stu_id ,stu_name ) values(2001,'小五');
    2、查询名字为Tom的学生所选的课程:select c_name from course where c_id in ( select c_id from student,score where student.stu_id=score.stu.id and student.stu.name='TOM')
    3、查询stu_id为3的学生所学课程的成绩
    select score,c_name from score ,course where score.stu_id =3 and course.c_id=score.stu_id

    2019-07-17 19:06:33
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
搭建电商项目架构连接MySQL 立即下载
搭建4层电商项目架构,实战连接MySQL 立即下载
PolarDB MySQL引擎重磅功能及产品能力盛大发布 立即下载

相关镜像