首页 > 数据库技术 > 详细

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

时间:2015-07-08 14:13:24      阅读:302      评论:0      收藏:0      [点我收藏+]

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

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岁的学生人数

原文:http://www.cnblogs.com/Devilwx/p/4629990.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!