日期:2014-05-17 浏览次数:20984 次
select st.name,count(si.id) from t_school_type st left join t_school_info si on st.id = si.t_s_id where si.record_status = 1 group by st.name;
select st.name,count(si.id) from t_school_type st left join (select * from t_school_info where record_status = 1)si on st.id = si.t_s_id group by st.name;
------解决方案--------------------
select st.name,count(si.id)
from t_school_type st
left join t_school_info si on st.id = si.t_s_id
where si.record_status = 1
group by st.name;
------------------------------
the result will be
STEP 1:
select * from t_school_type st left join t_school_info si on st.id = si.t_s_id;
this sql will find out every entry in table t_school_type;
we can name the result as "resulttable"
but after you add where condition
STEP 2:
select name,count(id) from resulttable where record_status=1 group by name;
the result will be filted.
So that's why you got the result like that, it's true.