mysql
--
SELECT DATE_FORMAT(START_DATE, '%m') AS MONTH, CAR_ID, COUNT(HISTORY_ID) AS RECORDS
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
WHERE
CAR_ID IN
(SELECT CAR_ID FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
WHERE DATE_FORMAT(START_DATE, '%Y-%m') BETWEEN '2022-08' AND '2022-10'
GROUP BY CAR_ID
HAVING COUNT(CAR_ID) >= 5
)
GROUP BY MONTH, CAR_ID
HAVING RECORDS >= 0
ORDER BY MONTH, CAR_ID DESC;
SELECT MONTH(START_DATE) AS MONTH, CAR_ID, COUNT(HISTORY_ID) AS RECORDS
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
WHERE CAR_ID IN (
SELECT CAR_ID
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
WHERE (DATE_FORMAT(START_DATE, '%Y-%m') BETWEEN '2022-08' AND '2022-10')
GROUP BY CAR_ID
HAVING COUNT(CAR_ID) >= 5
ORDER BY MONTH ASC, CAR_ID DESC;
SELECT MONTH(START_DATE) AS MONTH, CAR_ID, COUNT(HISTORY_ID) AS RECORDS
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
WHERE CAR_ID IN (
SELECT CAR_ID
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
WHERE DATE_FORMAT(START_DATE, '%Y-%m') BETWEEN '2022-08' AND '2022-10'
GROUP BY CAR_ID
HAVING COUNT(*) >= 5
)
GROUP BY MONTH, CAR_ID
HAVING RECORDS > 0
ORDER BY MONTH, CAR_ID DESC;
728x90
':: DBMS ๐ฉ > ํ๋ก๊ทธ๋๋จธ์ค SQL ๊ณ ๋์ kit ํ์ด' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
JOIN>์ํ ๋ณ ์คํ๋ผ์ธ ๋งค์ถ ๊ตฌํ๊ธฐ (0) | 2023.02.26 |
---|---|
JOIN>์กฐ๊ฑด์ ๋ง๋ ๋์์ ์ ์ ๋ฆฌ์คํธ ์ถ๋ ฅํ๊ธฐ (0) | 2023.02.26 |
GROUP BY>์นดํ ๊ณ ๋ฆฌ ๋ณ ๋์ ํ๋งค๋ ์ง๊ณํ๊ธฐ (0) | 2023.02.26 |
GROUP BY>์ฑ๋ถ์ผ๋ก ๊ตฌ๋ถํ ์์ด์คํฌ๋ฆผ ์ด ์ฃผ๋ฌธ๋ (0) | 2023.02.26 |
GROUP BY>์ง๋ฃ๊ณผ๋ณ ์ด ์์ฝ ํ์ ์ถ๋ ฅํ๊ธฐ (0) | 2023.02.26 |
๋๊ธ