--- TRUNCATE 활용
SELECT TRUNCATE(PRICE, -4) PRICE_GROUP, COUNT(*) COUNT
FROM PRODUCT
GROUP BY PRICE_GROUP
ORDER BY PRICE_GROUP
TURNCATE()
TRUNCATE(값, 자릿수)
: 자릿수까지 나타내도록 버림
--- 예시
SELECT TRUNCATE(1.234, 2) --- 1.23
SELECT TRUNCATE(12345, -4) --- 10000
FLOOR()
FLOOR(값)
: 소수점 뒤를 버림
--- 예시
SELECT FLOOR(1.234) --- 1
SELECT FLOOR(12345/10000) * 10000 --- 10000
그 외
ROUND(값, 자릿수=1)
: 자리수까지 나타내도록 반올림
--- 예시
SELECT ROUND(1.567, 2) --- 1.57
SELECT ROUND(1.567) --- 2
CEIL(값)
: 소수점 뒤를 올림
--- 예시
SELECT CEIL(1.234) --- 2
SELECT CEIL(1.567) --- 2
--- 범위가 0부터 90000이라는 가정 하에 = 범위에 제약을 받음
SELECT CASE WHEN (PRICE >= 0) AND (PRICE < 10000) THEN 0
WHEN (PRICE >= 10000) AND (PRICE < 20000) THEN 10000
WHEN (PRICE >= 20000) AND (PRICE < 30000) THEN 20000
WHEN (PRICE >= 30000) AND (PRICE < 40000) THEN 30000
WHEN (PRICE >= 40000) AND (PRICE < 50000) THEN 40000
WHEN (PRICE >= 50000) AND (PRICE < 60000) THEN 50000
WHEN (PRICE >= 60000) AND (PRICE < 70000) THEN 60000
WHEN (PRICE >= 70000) AND (PRICE < 80000) THEN 70000
WHEN (PRICE >= 80000) AND (PRICE < 90000) THEN 80000
WHEN (PRICE >= 90000) AND (PRICE < 100000)THEN 90000
END AS PRICE_GROUP, COUNT(*) COUNT
FROM PRODUCT
GROUP BY PRICE_GROUP
ORDER BY PRICE_GROUP