메뉴 바로가기 검색 및 카테고리 바로가기

한빛미디어

뇌를 자극하는 SQL Server

뇌를 자극하는 SQL Server 질의응답 게시판입니다.

P237의 상이한 결과에 대해

2013-01-23

|

by ilhase

1679

select SUM(price*amount) from #tmpTbl;
go
는 45500이 나옵니다.

그런데,
declare @total bigint --총구매액을 나타낼 누적변수
declare @priceXamount int --가격과 수량을 곱한 값
declare @num int --구매 테이블의 순번 열의 증가
declare @count int --전체 행의 숫자

set @total=0
set @num=1

select @count=COUNT(*) from #tmpTbl;

set @count=@count+1

while @count <> @num
begin
        select @priceXamount = price * amount from #tmpTbl
                where num = @num
        set @num = @num+1
        set @total = @total+@priceXamount
end

print @total
go

의 결과는 46240이 나옵니다. 왜그럴까요?
댓글 입력