본문 바로가기
Projects

[매출 관리 프로그램 제작] - 쿼리 제작

by Runningturtle 2024. 8. 16.

지난 포스팅에서 Ui를 제작하였다.

 

이에 이어서  프로그램 실행에 필요한 쿼리를 만들기로 계획.

 

아래는 만든 쿼리들이다.

 

//기능1번쿼리  (지정구간 날짜 매출)
select a.transaction_date,SUM(REVENUE) from (select transaction_date,revenue from cafe_sales_report where TRANSACTION_DATE between TO_DATE('2023-01-01','YYYY-MM-DD') AND TO_DATE('2023-01-02','YYYY-MM-DD'))A group by A.TRANSACTION_DATE; 

//기능2번쿼리 (지점별 각 메뉴의 매출)
select CASE WHEN row_number() over(partition by store_location order by product_category) = 1 then store_location else ' ' END AS store_location,product_category,count(*) from cafe_sales_report group by rollup(store_location,product_category) ; 
 
//기능3번쿼리 (모든날짜 지점별 매출)
select transaction_date,store_location,sum(revenue) as revenue from cafe_sales_report group by transaction_date,store_location order by transaction_date,store_location;
/* 3번쿼리 검증 */
select transaction_date,store_location,sum(revenue) from cafe_sales_report where  transaction_date = '2023-01-01' group by transaction_date,store_location order by 3 desc; 
 
 //기능4번쿼리 (데이터 수정)
 update cafe_sales_report set A=B where transaction_id= C ;  // A=수정 할 속성 B= 수정할 값 C=기본키

 

 

 

1번쿼리 결과

 

2번쿼리 결과

 

3번 쿼리 결과

 

 

각 기능을 수행할 쿼리를 만들면서 검증도 함께 진행하였다.

 

쿼리를 만들면서 CASE - WHEN - END 조건문과 over(), partition by를 적용

 

 

 

 

 

프로그램 실행계획을 구체화 시킬 대략적 시나리오 작성

 

 

이로써 쿼리 제작을 마친다.