mysql重點題目--查詢“01“課程比“02“課程成績高的學生的資訊及課程分數

中國碼農*發表於2020-10-04

– 1、查詢"01"課程比"02"課程成績高的學生的資訊及課程分數

我的答案:

select 
st.*,
sc.s_score '語文',
sc2.score2 '數學',
inner join score sc on sc.s_id =st.s_id and sc.c_id='01'
inner 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 AS '語文',
sc2.s_score AS '數學'

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

相關文章