select a.sno from (select sno from t where subject='语文&(8803)#39; and score>=60) a inner join (select sno from t where subject='数学&(8804)#39; and score<60) b on a.sno=b.sno
这种题目的话我觉得面试官一般是想考我们行列转换的内容,我面了一些都要考这个考点,所以我们可以先进行行列转换,再筛选就清晰很多了 select SNO from ( select SNO, case SUBJECT when "语文" then SCORE end as chinese_score, case SUBJECT when "数学" then SCORE end as maths_score from table1 ) where chinese_score >= 60 and maths_score <60
select SNO from (select SNO, sum(case subject when'语文&(8803)#39; then score else null end) as chinese_score, sum(case subject when'数学&(8804)#39; then score else null end) as math_score from t group by SNO ) as tt where tt.chinese_score>=60 and tt.math_score<60 ===================================== 如果是case subject ……else 0的话结果就会多了一个1002
select stu_id from exam where course = '语文&(8803)#39; and score >= 60 and stu_id in ( select stu_id from exam where course = '数学&(8804)#39; and score < 60)
select stu_id, sum(case course when "语文" then SCORE else 0 end) as chinese_score, sum(case course when "数学" then SCORE else 0 end) as maths_score from exam group by stu_id having chinese_score >= 60 and maths_score <60
select distinct SNO from T where SNO in (select SNO from T where subject='语文&(8803)#39; and score>=60) and SNO in (select SNO from T where subject='数学&(8804)#39; and score<60)
select a.sno from (select * from sqltest where subject = '语文&(8803)#39; and score >= 60) as a inner join (select * from sqltest where subject = '数学&(8804)#39; and score <60) as b on a.sno = b.sno select a.sno from (select sno, sum(case subject when '语文&(8803)#39; then score else null end) as chinese_score, sum(case subject when '数学&(8804)#39; then score else null end) as match_score from sqltest group by sno) as a where a.chinese_score >= 60 and a.match_score < 60
select sno from T group by sno having sum(case subject when '语文&(8803)#39; then score else null end) >= 60 and sum(case subject when '数学&(8804)#39; then score else null end) < 60
select y.SNO from ( select * from T where subject='语文&(8803)#39; ) y join ( select * from T where subject='数学&(8804)#39; ) s on y.SNO =s.SNO where y.score>=60 and s.score <60; 这样可以吗?
Select a.sno from (Select sno from t Where subject = '语文&(8803)#39; and score >= 60) a Inner join (select sno from t Where subject = '数学&(8804)#39; and score < 60) b On a.sno = b.sno