Story/mysql
mysql query 를 이용해 달력 만들기
Stdio
2011. 11. 15. 12:07
반응형
SELECT SUM(if(A.A2 = '6', A.A3, null)) as 일요일,
SUM(if(A.A2 = '0', A.A3, null)) as 월요일,
SUM(if(A.A2 = '1', A.A3, null)) as 화요일,
SUM(if(A.A2 = '2', A.A3, null)) as 수요일,
SUM(if(A.A2 = '3', A.A3, null)) as 목요일,
SUM(if(A.A2 = '4', A.A3, null)) as 금요일,
SUM(if(A.A2 = '5', A.A3, null)) as 토요일
FROM
(
SELECT
WEEK(DATE_FORMAT(CONCAT('200608','01'),'%Y%m%d')) - WEEK(DATE_FORMAT(concat('2006-08-' ,Id), '%Y-%m-%d')) as A1,
WEEKDAY(DATE_FORMAT(concat('2006-08-' ,Id), '%Y-%m-%d')) as A2,
Id as A3
FROM
test
where
Id <= DATE_FORMAT( LAST_DAY(DATE_FORMAT(CONCAT('200608','01'),'%Y%m%d')),'%d' )
) A
GROUP BY A.A1
order by A.A1 desc
SUM(if(A.A2 = '0', A.A3, null)) as 월요일,
SUM(if(A.A2 = '1', A.A3, null)) as 화요일,
SUM(if(A.A2 = '2', A.A3, null)) as 수요일,
SUM(if(A.A2 = '3', A.A3, null)) as 목요일,
SUM(if(A.A2 = '4', A.A3, null)) as 금요일,
SUM(if(A.A2 = '5', A.A3, null)) as 토요일
FROM
(
SELECT
WEEK(DATE_FORMAT(CONCAT('200608','01'),'%Y%m%d')) - WEEK(DATE_FORMAT(concat('2006-08-' ,Id), '%Y-%m-%d')) as A1,
WEEKDAY(DATE_FORMAT(concat('2006-08-' ,Id), '%Y-%m-%d')) as A2,
Id as A3
FROM
test
where
Id <= DATE_FORMAT( LAST_DAY(DATE_FORMAT(CONCAT('200608','01'),'%Y%m%d')),'%d' )
) A
GROUP BY A.A1
order by A.A1 desc
반응형