임 : 앞으로 십년 10 년 전다음 필드 MySQL의 테이블을 만들려고 노력
분 년, 월, 일,시,.
나는 일을 만듭니다이있다, 그러나 그것은 시간과 분을 포함 나던SET @d0 = "2012-01-01";
SET @d1 = "2012-12-31";
SET @date = date_sub(@d0, interval 1 day);
# set up the time dimension table
DROP TABLE IF EXISTS time_dimension;
CREATE TABLE `time_dimension` (
`date` date DEFAULT NULL,
`id` int NOT NULL,
`y` smallint DEFAULT NULL,
`m` smallint DEFAULT NULL,
`d` smallint DEFAULT NULL,
`yw` smallint DEFAULT NULL,
`w` smallint DEFAULT NULL,
`q` smallint DEFAULT NULL,
`wd` smallint DEFAULT NULL,
`m_name` char(10) DEFAULT NULL,
`wd_name` char(10) DEFAULT NULL,
PRIMARY KEY (`id`)
);
# populate the table with dates
INSERT INTO time_dimension
SELECT @date := date_add(@date, interval 1 day) as date,
# integer ID that allows immediate understanding
date_format(@date, "%Y%m%d") as id,
year(@date) as y,
month(@date) as m,
day(@date) as d,
date_format(@date, "%x") as yw,
week(@date, 3) as w,
quarter(@date) as q,
weekday(@date)+1 as wd,
monthname(@date) as m_name,
dayname(@date) as wd_name
FROM T
WHERE date_add(@date, interval 1 day) <= @d1
ORDER BY date
;
내가 어떻게 수정할 수 있도록 그것은 또한 시간과 분을합니까? 감사합니다.
여기에 타임 스탬프를 사용하지 않으려는 이유가 있습니까? 많은 다른 시간 구성 요소를 관리하는 것이 어느 시점에서 더러워 질 수 있다고 생각합니다. –
하지만 whhhyyyyy? 오, 인류 :-( – Strawberry
20 년 내에 매분의 시간 기록을 저장하는 테이블의 목적은 무엇입니까? – BeetleJuice