티스토리 뷰

728x90

 

MySQL에서는 월요일부터 일요일까지 0~7로 나타내므로 case문을 사용해서 한글로 출력하면 된다

 

SELECT CASE a.a
WHEN '0' THEN '월'
WHEN '1' THEN '화'
WHEN '2' THEN '수'
WHEN '3' THEN '목'
WHEN '4' THEN '금'
WHEN '5' THEN '토'
WHEN '6' THEN '일'
END AS week, IFNULL( b.cnt, 0 ) AS cnt
FROM (
SELECT a.a
FROM (
SELECT 0 AS a
UNION ALL SELECT 1
UNION ALL SELECT 2
UNION ALL SELECT 3
UNION ALL SELECT 4
UNION ALL SELECT 5
UNION ALL SELECT 6
) AS a
)a
LEFT JOIN (
SELECT WEEKDAY( alarm_date ) AS week, COUNT( alarm_date ) AS cnt
FROM alarm
GROUP BY WEEKDAY( alarm_date )
)b ON a.a = b.week;";
728x90
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함