-- 집계함수

 

-- 샘플테이블

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 값은제외해서카운트




'.NET프로그래밍 > SQL Server 2008' 카테고리의 다른 글

24. 문자열관련함수  (0) 2009.09.11
23. 수학관련함수  (0) 2009.09.11
21. 테이블제약조건  (0) 2009.09.11
20. 제어문 - while문  (0) 2009.09.11
19. 제어문 - if문  (0) 2009.09.11
Posted by holland14
: