本人初学java。请各位大牛帮帮忙。
学生表student (stu_id ,stu_name ); 课程表course (c_id,c_name);
成绩表score (stu_id ,c_id,score);
1、在学生表中添加一条数据:
2、查询名字为Tom的学生所选的课程:
3、查询stu_id为3的学生所学课程的成绩
我觉得做个视图比较好啊。这个没必要多表查。
insert into student values(id,name);
select course.c_name form student ,course ,score where student.stu_name = 'Tom' and student.stu_id = score_stu_id and score.c_id = course.c_id;
select score from student ,course where student.stu_id=3 and student.stu_id = score_stu_id;
学生表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
一楼写的第二个问题错误,
```select course.c_name form student ,course ,score where student.stu_name = 'Tom' and student.stu_id = score_stu_id and score.c_id = course.c_id;
这里只说查TOM的课程,与成绩表无关。
3楼给的是正解。楼主可以采纳。
1.insert into student value(1,'John');
2. select c_id, c_name from student, course, score where student.stu_id = score.stu_id and score.c_id = course.c_id and student.stu_name = ''Tom;
3. select score.score from course, score where score.c_id = course.c_id and score.stu_id = 3;
学生表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(1,"aaa");
2、查询名字为Tom的学生所选的课程: select c_name form course ,student,score where course..c_id=score.c_id and score.stu_id=student.stu_id and student.stu_name="Tom"
="Tom"
3、查询stu_id为3的学生所学课程的成绩 select score form score wherescore.stu_id=3
这个就是SQL查询的问题,很简单吧