[Oracle] 조건 카운트

hi·2022년 2월 24일
0

table 1
table 2


🔎 subject 컬럼별로 A등급 학생 수 카운트하기
    (=조건에 일치하는 경우 카운트)

SELECT COUNT(CASE WHEN 조건 THEN 1 END) FROM 테이블
select 
	count(case when loscore<=m_subject1 and m_subject1<=hiscore then 1 end) as m_subject1,
	count(case when loscore<=m_subject2 and m_subject2<=hiscore then 1 end) as m_subject2,
	count(case when loscore<=m_subject3 and m_subject3<=hiscore then 1 end) as m_subject3,
	count(case when loscore<=s_subject1 and s_subject1<=hiscore then 1 end) as s_subject1,
	count(case when loscore<=s_subject2 and s_subject2<=hiscore then 1 end) as s_subject2
from score_tbl natural join (select *
							 from grade_tbl
							 where grade='A'); 


결과

0개의 댓글