日期:2014-05-16 浏览次数:20717 次
select 学生id,name,c.class_name,(select count(*) from student where class_id=s.class_id) as 所在班级人数 from student s ,classes c where s.class_id=c.id
------解决方案--------------------
select s.id,s.name,c.class_name,count(*) from student s ,classes c where s.class_id=c.id group by s.id,s.name,c.class_name
------解决方案--------------------
select 学生id,name,c.class_name,(select count(*) from student where class_id=A.class_id)
from student A INNER JOIN classes B ON A.class_id=B.id
------解决方案--------------------
select a.id,a.name,b.class_name,(select count(*) from student where class_id=A.class_id)as'班级人数' from student a left join classes b on a.id=b.class_id;