
CREATE procedure exam_calc(_page int,_ppcnt int)
BEGIN
DECLARE _kor int;
DECLARE _eng int;
DECLARE _mat int;
DECLARE _sum int;
DECLARE _ave int;
DECLARE _start int;
####################
drop table if exists exam_calc_temp;
create table exam_calc_temp(
title varchar(50),
kor integer,
eng integer,
mat integer,
sum integer,
ave integer
);
insert into exam_calc_temp(title, kor, eng, mat)
select goodjob.studentid, goodjob.kor, goodjob.eng, goodjob.mat from goodjob limit 0,30;
update exam_calc_temp set sum=kor+eng+mat;
update exam_calc_temp set ave=sum/3;
####################
## 들어온 페이지로 _start와 _cnt구하기
set _start = (_page-1) *_ppcnt +1; ## 해당 페이지의 시작번호...
## 페이지당 합계계산
SELECT sum(kor) INTO _kor FROM examtable Limit _start,_ppcnt;
SELECT sum(eng) INTO _eng FROM examtable Limit _start,_ppcnt;
SELECT sum(mat) INTO _mat FROM examtable Limit _start,_ppcnt;
SELECT sum(sum) INTO _sum FROM examtable Limit _start,_ppcnt;
SELECT sum(ave) INTO _ave FROM examtable Limit _start,_ppcnt;
INSERT INTO reserv_stat VALUE ("페이지별 합계",_kor,_eng,_mat,_sum,_ave);
###나머지는 계속 알아서 해라
END $$
DELIMITER ;
call exam_calc();
select * from exam_calc_temp;
mysql> create procedure exam_calc(paga int, ppcnt int) begin end;
Query OK, 0 rows affected (0.01 sec)
mysql> call exam_calc(30, 1);
Query OK, 0 rows affected (0.00 sec)
mysql> drop procedure if exists exam_calc;
Query OK, 0 rows affected (0.02 sec)