[sql] 카테고리별 매출 계산 (ABC 분석, 팬차트, 히스토그램)
카테고리별 매출 소계 집계 select substring(date::text, 6, 2) as months ,category , sum(amount) as total_amount from sale_data group by ROLLUP(months, category) order by months, category ABC 분석 with month_sales as ( select category , sum(amount) as amount from sale_data where date between '2019-01-01' and '2019-01-31' group by category ) , sales_ratio as ( select category ,amount ,round(100.0 * amount / sum..
2022. 9. 26.
[sql] STRING_SPLIT 함수, 구분자로 자르기, 행열 변환
STRING_SPLIT 함수, 구분자로 자르기 select top 100 * from ( select purchase_id ,product_ids from purchase_log ) as x cross apply string_split (product_ids, ',') as y --- 쉼표로 묶어진 컬럼을 하나로 value 형식으로 따내는 법 --- 결과값 purchase_id product_ids value 100001 A001,A002,A003 A001 100001 A001,A002,A003 A002 100001 A001,A002,A003 A003 100002 D001,D002 D001 100002 D001,D002 D002 100003 A001 A001 행열 변환하는 방법 /* 행 열 변환 SELE..
2022. 9. 26.