시소당
:배치 테이블과 온라인 테이블을 이용하여 온라인 속도를 높이는 질의
당월의 마지막날에는 마감후 합계정보가 있고, 어제까지의 합계가 어제 날짜에 있다.
Select Col1, SUM(Col2) …
From (select col1, col2 …
from 집계테이블
Where 집계일자 between ‘960101’ and ‘960427’
Union all
Select FLD1 as Col1, FLD2 as Col2…
From 현재테이블
where 처리일자 beween ‘960428’ and ‘’960429’
group by Col1;
 일별 집계 테이블에서 직접온라인 조회
:월별통계정보에는 매월의 합계값이 YYMM(KEY)로 저장되어 있고, 일별통계정보는 매일의 값이 YYMMDD(KEY)로 저장되어 있다.
select v.영업월, v.평가금액합
from (select subst(영업일,1,4) as 영업월, sum(평가금액) as 평가금액합
from 일별통계정보
where 지점정보 = :B1
and ((영업일 between :s_date
and to_char(last_day(to_date(:s_date,’YYMMDD’)),’YYMMDD’)
group by substr(영업일,1,4)
union all
select 영업월, 평가금액 as 평가금액합
from 월별통계정보
where 지점번호 = : B1
and 영업월 >= subst(to_char(add_months(to_date(:s_date,’yymmdd’),1),’yymmdd’)1,4)
and 영업월 <= subst(to_char(add_months(to_date(:s_date,’yymmdd’),-1),’yymmdd’)1,4)) v
order by v.영업월;