/*
SQL是3个表的查询,会给出表以及3个表之间的约束关系
Student 表
No编号
Name 姓名
Birthday 生日
bj 班级
jg 籍贯
adds地址
number电话
Course 表
Kcbh课程编号
kcmc课程名称
Source 表
Cjguid (主键)
No 编号
kcbh 课程编号
cj成绩
*/
-- (1)查询学生籍贯为‘湖北’生日为1995-10-3的所有信息
select *
from Student
where 1=1
and jg = '湖北' -- 籍贯为‘湖北’
and Birthday = '1995-10-3' -- 生日为1995-10-3
-- (2)查询学生姓名为‘王华’的各课程的平均分,最高分,最低分,总分。
select
avg(kcbh) as 平均分,
max(kcbh) as 最高分,
min(kcbh) as 最低分,
sum(kcbh) as 总分
from Source
where 1=1
and exists (select 1
from Student.
where 1=1
and Student.No = Source.No
Name = '王华' -- 姓名为‘王华’
)
-- (3)没有太看题,大致是要求查询4,5列以上的信息,其中3个表各包含一些信息
select
Student.Name as 学生,
Course.kcmc as 课程,
Source.cj as 成绩
from Student,
Course,
Source,
where 1=1
and Student.No = Source.No
and Course.Kcbh = Source.kcbh