赞
踩
select st.*,sc.s_Score as '语文' ,sc2.s_Score '数学'
from Student st
left join Score sc on sc.s_id=st.s_id and sc.c_id='01'
left join Score sc2 on sc2.s_id=st.s_id and sc2.c_id='02'
where sc.s_Score>sc2.s_Score;
select st.*,sc.s_Score '语文',sc2.s_Score '数学'
from Student st
left join Score sc on sc.s_id=st.s_id and sc.c_id='01'
left join Score sc2 on sc2.s_id=st.s_id and sc2.c_id='02'
where sc.s_Score<sc2.s_Score;
select st.s_id,st.s_name,ROUND(AVG(sc.s_Score),2) cjScore
from Student st
left join Score sc on sc.s_id=st.s_id
group by st.s_id having AVG(sc.s_Score)>=60;
select st.s_id,st.s_name,(case when ROUND(AVG(sc.s_Score),2) is null then 0 else ROUND(AVG(sc.s_Score)) end ) cjScore
from Student st
left join Score sc on sc.s_id=st.s_id
group by st.s_id having AVG(sc.s_Score)<60 or AVG(sc.s_Score) is NULL;
select st.s_id,st.s_name,count(sc.c_id) '选课总数',(case when sum(sc.s_Score) is null or sum(sc.s_Score)='' then 0 else sum(sc.s_Score) end) '总成绩'
from Student st
left outer join Score sc on st.s_id=sc.s_id
group by st.s_id;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。