22. 집계 함수
-- 집계함수
-- 샘플테이블
Create Table dbo.Score
(
Num Int Identity(1, 1) Primary Key, -- 일련번호
Kor Int Not Null, -- 국어점수
Eng Int Null -- 영어점수
)
Go
-- 샘플데이터입력
Insert Score Values(100, 90)
Insert Score Values(80, 75)
Insert Score Values(85, 90)
Insert Score Values(85, NULL)
-- 전체출력
Select * From Score
Go
-- 국어점수짝수점수의총점/평균/카운트
Select SUM(Kor) From Score Where Kor % 2 = 0 -- Sum() : 합계
Select Count(Kor) From Score Where Kor % 2 = 0 -- Count() : 건수
Select Avg(Kor) From Score Where Kor % 2 = 0 -- Avg(): 평균
Select Max(Kor) From Score Where Kor % 2 = 0 -- Max() : 최대값
Select Min(Kor) From Score Where Kor % 2 = 0 -- Min : 최소값
--
Select Count(*) From Score -- 4
Select Count(Kor) From Score -- 4
Select Count(Eng) From Score -- 3 : NULL 값은제외해서카운트