Recap - Total Gain Shop
Coddy SQL 여정의 기초 섹션에 포함된 레슨. 72개 중 40번째.
챌린지
쉬움사용 가능한 테이블 및 열:
<strong>shop</strong>:<strong>price</strong>,<strong>quantity</strong>,<strong>category</strong>,<strong>list_date</strong>
당신의 작업은 January 1, 2015부터 March 18, 2015 사이의 상점 내 각 category별 총매출을 계산하는 것입니다. 데이터 입력 시스템의 계통 오차로 인해 데이터베이스의 모든 price 값이 고정된 금액만큼 실제보다 낮게 입력되었습니다.
이 가격들을 수정하려면 다음과 같이 하세요:
first, 지정된 날짜 범위(2015-01-01(January 1, 2015)부터2015-03-18March 18, 2015) 내의 모든 항목에 대한 평균price를 계산합니다.- 이 평균
price를 각 항목의originalprice에 더하여correctedprice값을 구합니다. eachcategory에 대해correctedprice에quantity를 곱하고 이 값들을 합산하여total매출을 계산합니다.- 결과를 (
category,total_revenue) 쌍으로 제시하고,total_revenue기준 내림차순으로ORDER정렬합니다.
직접 해보기
-- 2단계: 재구성된 행들을 그룹화하고 합계를 내며, 가장 큰 것부터
SELECT ____
FROM (
-- 1단계: 수정된 값이 원래 값을 대체하도록 각 행을 재구성
SELECT ____ AS price, quantity, category, list_date
FROM shop
WHERE list_date BETWEEN '2015-01-01' AND '2015-03-18'
)
GROUP BY ____
ORDER BY ____ DESC기초의 모든 레슨
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columns직접 연습해 보세요: SQL 플레이그라운드