SQL 语句查询所有参加考试的学生,从Stu表中和Sco表中

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL 语句查询所有参加考试的学生,从Stu表中和Sco表中相关的知识,希望对你有一定的参考价值。

这个是表的结构,另外我把其他几问也告诉大家,大家帮帮我!!
(1) 查询stu表中年龄的平均值,最大值,最小值。
(2) 查询stu表中学生人数。
(3) 查询stu表中李姓学生的信息。(
(4) 查询stu表中李姓学生的姓名和笔试成绩
(5) 查询比‘李斯文’年龄大的学员信息(
(6) 查询实验成绩及格的学生姓名
(7) 查询所有参加考试的学生信息
(8) 查询所有没参加考试的学生信息

select * from score(成绩表) where stuno(考号) in (select stuno from student)
思路是这样的,学生表中有的考号在成绩表中出现,就叫做参加考试了,更详细的就是说,机试和笔试成绩都不为null
参考技术A select * from stu,sco and stu.stuNo=sco.stuNo
1.select avg(stuAg), max(stuAg),min(stuAg) from stu
2.select count(*) from stu
3.select * from stu where stuName like ‘李%’
4。select stuName writtenExam from stu,sco where stuName like ‘李%’and stu.stuNo=sco.stuNo
5.select * from stu where (stuAge>(select lstuAge from stu where stuName='李斯文' ))//试一下,应该可以
6.select stuName from stu,sco where LabExam>=60 and stu.stuNo=sco.stuNo
7.select * from stu,sco where stu.stuNo=sco.stuNo
8.select * from stu,sco where not(stu.stuNo=sco.stuNo)
参考技术B 1
select avg(stuAge),max(stuAge),min(stuAge) from Stu

2
select count(stuNo) from Stu

3
select * from Stu where stuName='李%'

4
select Stu.stuName,Sco.virttenExam from Stu,Sco where Stu.stuNo=Sco.stuNo and Stu.stuName='李%'

5
select * from Stu where stuAge>(select stuAge from Stu where stuName='李斯文'

6
select Stu.stuName from Stu,Sco where Sco.LabExam>=60

7
select Stu.stuName,Stu.stuNo,Stu.stuSex,Stu.stuSeat,Stu.stuAddress from Sco,Stu
where Sco.stuNO=Stu.stuNo and (vrittenExam is null or LabExam is null)

8
select Stu.stuName,Stu.stuNo,Stu.stuSex,Stu.stuSeat,Stu.stuAddress from Sco,Stu
where Sco.stuNO=Stu.stuNo and vrittenExam is null and LabExam is null
参考技术C select sname
from stu,sc
where stu.sno=sc.sno and grade is not null

mysql三表查询sql语句

  1. 表结构:

Student学生表(学号、姓名、性别、年龄、编辑)

Course课程表(编号、课程名称)

sc选课表(选课编号、学号、课程编号、成绩)

(1)写一个SQL语句,查询选修了“计算机原理”的学生学号和姓名

(2)写一个SQL语句,查询“小明”同学选修的课程名称

(3)写一个SQL语句,查询选修了5门课程的学生学号和姓名

 

答案:

1

select student.stu_no,student.stu_name

from student,course,sc

where course.c_no=sc.c_no and sc.stu_no=student.stu_no and course.c_name=‘计算机原理‘;

2

select course.c_name,student.stu_name

from student,course,sc

where student.stu_name=‘小明‘ and student.stu_no=sc.stu_no and sc.c_no=course.c_no;

3

select student.stu_no,stu_name

from student,course,sc

where student.stu_no=sc.stu_no and sc.c_no=course.c_no

group by student.stu_no

having count(*)=5

 

建表及插入数据可参考如下语句:

create table student(

stu_no int,

stu_name varchar(10),

sex char(1),

age int(3),

edit varchar(20)

);

 

insert into student values

(1,‘wang‘,‘‘,21,‘hello‘),

(2,‘小明‘,‘‘,22,‘haha2‘),

(3,‘hu‘,‘‘,23,‘haha3‘),

(4,‘li‘,‘‘,25,‘haha4‘);

 

create table course(

c_no int,

c_name varchar(10)

);

 

insert into course values

(1,‘计算机原理‘),

(2,‘java‘),

(3,‘c‘),

(4,‘php‘),

(5,‘py‘);

 

create table sc(

sc_no int,

stu_no int,

c_no int,

score int(3)

);

 

insert into sc values

(1,1,1,80),

(2,2,2,90),

(3,2,1,85),

(4,2,3,70),

(5,2,4,95),

(6,2,5,89);

以上是关于SQL 语句查询所有参加考试的学生,从Stu表中和Sco表中的主要内容,如果未能解决你的问题,请参考以下文章

mysql三表查询sql语句

用SQL语句查询每门成绩都大于80的学生姓名? 新手求教。。

SQL从零到迅速精通表连接查询

几道sql题求答案

在R中向量化复杂的dplyr语句

mysql条件查询