-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Day 28 - Programmers SQL 난이도 4 (#82)
* ✨ Day 28 - Programmers SQL 난이도 4 * 📗 class 명 변경
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
1번 : 자동차 대여 기록 별 대여 금액 구하기 | ||
- SELECT | ||
HISTORY_ID, | ||
ROUND(PERIOD * (1 - IFNULL(DISCOUNT_RATE,0)/100) * DAILY_FEE) as FEE | ||
FROM CAR_RENTAL_COMPANY_CAR crcc | ||
LEFT JOIN | ||
(SELECT HISTORY_ID, CAR_ID, (DATEDIFF(END_DATE, START_DATE) + 1) as PERIOD, CASE | ||
WHEN DATEDIFF(end_date, start_date) + 1 >= 90 THEN '90일 이상' | ||
WHEN DATEDIFF(end_date, start_date) + 1 >= 30 THEN '30일 이상' | ||
WHEN DATEDIFF(end_date, start_date) + 1 >= 7 THEN '7일 이상' | ||
ELSE null END AS DURATION_TYPE | ||
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY) as ccrh | ||
ON ccrh.CAR_ID = crcc.CAR_ID | ||
LEFT JOIN CAR_RENTAL_COMPANY_DISCOUNT_PLAN discount | ||
ON ccrh.DURATION_TYPE = discount.DURATION_TYPE | ||
AND crcc.CAR_TYPE = discount.CAR_TYPE | ||
WHERE crcc.CAR_TYPE = '트럭' | ||
ORDER BY FEE DESC, HISTORY_ID DESC | ||
|
||
2번 : 특정 기간동안 대여 가능한 자동차들의 대여비용 구하기 | ||
|
||
- SELECT | ||
crcc.CAR_ID, | ||
crcc.CAR_TYPE, | ||
ROUND(30 * (1 - DISCOUNT_RATE/100) * DAILY_FEE) as FEE | ||
FROM CAR_RENTAL_COMPANY_CAR crcc | ||
INNER JOIN CAR_RENTAL_COMPANY_DISCOUNT_PLAN ccdp | ||
ON ccdp.CAR_TYPE = crcc.CAR_TYPE AND ccdp.DURATION_TYPE = '30일 이상' | ||
WHERE crcc.CAR_TYPE IN ('세단', 'SUV') | ||
AND ROUND(30 * (1 - DISCOUNT_RATE/100) * DAILY_FEE) >= 500000 | ||
AND ROUND(30 * (1 - DISCOUNT_RATE/100) * DAILY_FEE) <= 2000000 | ||
AND crcc.CAR_ID NOT IN | ||
(SELECT CAR_ID | ||
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY | ||
WHERE start_date < '2022-11-30 00:00:00' AND end_date > '2022-11-01 00:00:00') | ||
GROUP BY crcc.CAR_ID | ||
ORDER BY FEE DESC, crcc.CAR_TYPE ASC, crcc.CAR_ID DESC |
File renamed without changes.