SQL求出小于45岁的各个老师所带的大于12岁的学生人数

这有两个语句,可是这两个语句的结果相同,但其他方面有什么区别呢?

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;

posted @ 2015-07-08 13:59  哎呦喂哈  阅读(775)  评论(0编辑  收藏  举报