时间:2021-07-01 10:21:17 帮助过:2人阅读
这有两个语句,可是这两个语句的结果相同,但其他方面有什么区别呢?
1.select count(ts.tid),ts.tid from t_s ts ,
(select tid from teacher where age<45 group by tid) t
where ts.tid=t.tid
and
ts.sid in (select sid from student where age>12 group by sid)
group by ts.tid;
2.
select teacher.tid,total from teacher ,
(select t_s.tid,count(*) total from student,t_s where student.sid=t_s.sid and student.age>12 group by t_s.tid) as tea_stu2
where
teacher.tid=tea_stu2.tid
and teacher.age<45;
SQL求出小于45岁的各个老师所带的大于12岁的学生人数
标签: