데이터의 최댓값을 구하는 함수

EX1) 시험성적 데이터의 최댓값

SELECT MAX(SCORE) AS MAX_SCORE FROM SQLD;

Untitled

EX2) 과목별 최대 점수 구하기

SELECT student_name, 
		   subject,
       score,
       MAX(score) OVER(PARTITION BY subject) as max_score
FROM sqld
ORDER BY score;

Untitled

EX3) 과목별 최대 점수를 받은 사람만 출력하기

SELECT student_name,
	   subject,
       score
FROM (
	 SELECT student_name, 
			subject,
			score,
			MAX(score) OVER(PARTITION BY subject) as max_score
	  FROM sqld) as drived_table
WHERE score = max_score;

(as drived_table 이 부분이 없었을 때 MySQL에서는 에러가 발생했었다.)

Untitled