select Student.*,sc1.s_Score '语文' ,sc2.s_Score '数学'
from Student
left join Score sc1 on sc1.s_id=Student.s_id and sc1.c_id='01'
left join Score sc2 on sc2.s_id=Student.s_id and sc2.c_id='02'
where sc1.s_Score>sc2.s_Score;
select Student.*,sc1.s_Score '语文' ,sc2.s_Score '数学'
from Student
left join Score sc1 on sc1.s_id=Student.s_id and sc1.c_id='01'
left join Score sc2 on sc2.s_id=Student.s_id and sc2.c_id='02'
where sc1.s_Score<sc2.s_Score;
select Student.s_id,Student.s_name,AVG(Score.s_Score) '平均分'
from Student
left join Score on Score.s_id=Student.s_id
group by Student.s_id having AVG(Score.s_Score)>=60;
select Student.s_id,Student.s_name,AVG(Score.s_Score) '平均分'
from Student
left join Score on Score.s_id=Student.s_id
group by Student.s_id having AVG(Score.s_Score)<60 or AVG(Score.s_Score) is NULL
select Student.s_id,Student.s_name,count(Score.c_id) '选课总数',ifnull(sum(Score.s_Score),0) '总成绩'
from Student
left join Score on Student.s_id=Score.s_id
group by Student.s_id
select Teacher.t_name,count(Teacher.t_name) '总数' from Teacher
group by Teacher.t_id having Teacher.t_name like '李%'
?
select Student.* from Student
left join Score on Score.s_id=Student.s_id
left join Course on Course.c_id=Score.c_id
left join Teacher on Teacher.t_id=Course.t_id
where Teacher.t_name="张三";
select Student.* from Student where Student.s_id not in(
select Score.s_id from Score where Score.c_id in (select Course.c_id from Course left join Teacher t on t.t_id=Course.t_id where t.t_name="张三")
)
select s.*
from Score sc1
join Score sc2
on
sc1.s_id=sc2.s_id
and
sc1.c_id=01
and
sc2.c_id=02
left join Student s
on
s.s_id=sc1.s_id;
select Student.* from Student
inner join Score on Score.s_id = Student.s_id and Score.c_id="01"
where Student.s_id not in (
select st2.s_id from Student st2
inner join Score sc2 on sc2.s_id = st2.s_id and sc2.c_id="02"
);