Sql
월별 누적 조회 쿼리
pakker
2021. 4. 2. 15:29
지점 별, 판매 월별 매출이 나타난 table이 있다.
이 테이블의 지점 별 달마다의 누적 매출을 구하려면? oracle
select 지점, 판매월, 매출,
sum(매출) over (partition by 지점 order by 판매월
range between unbounded preceding and current row) 누적매출
from 월별 지점 매출
윈도우 함수가 지원되지 않는다면?
select t1.지점, t1.판매월, min(t1.매출) 매출, sum(t2.매출) 누적매출
from 월별지점매출 t1, 월별지점매출 t2
where t2.지점 = t1.지점 and t2.판매월 <= t1.판매월
group by t1.지점, t1.판매월
order by t1.지점, t1.판매월