반응형
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
반응형
'Story > mysql' 카테고리의 다른 글
mysql uft-8 로 데이타 넣을때 (0) | 2011.11.15 |
---|---|
mysql 사용자 추가 쿼리 (0) | 2011.11.15 |
디비내용을 csv 로 저장하기 (0) | 2011.04.04 |
주민등록 번호로 나이,나이대 구하기 (0) | 2011.03.18 |
string split 구분자로 저장된것을 다른 테이블과 join (0) | 2009.01.22 |