목록날짜계산 (1)
happy coding
[programmers] 자동차 평균 대여 기간 구하기
SELECT CAR_ID, CASE WHEN ROUND(AVG(DATEDIFF(END_DATE, START_DATE)), 1) >= 7 THEN ROUND(AVG(DATEDIFF(END_DATE, START_DATE)), 1) ELSE 0 END AS AVERAGE_DURATION FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY GROUP BY CAR_ID HAVING AVERAGE_DURATION != 0 ORDER BY AVERAGE_DURATION DESC, CAR_ID DESC; 이따구로 짰는데 결과는 '틀렸습니다.'였다. 너무 복잡하게 한 것 같아서 다시 코딩 SELECT CAR_ID, ROUND(AVG(DATEDIFF(END_DATE, START_DATE)+1),1) AS..
self study/Database
2023. 8. 15. 16:13