CREATE TABLE `praise_info` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`pic_id` varchar(64) DEFAULT NULL COMMENT '圖片ID',
`created_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '創(chuàng)建時間',
PRIMARY KEY (`id`),
KEY `pic_id` (`pic_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=3647 DEFAULT CHARSET=utf8 COMMENT='圖片表';
SELECT * FROM
(
SELECT *, @num := if(@created_time = DATE_FORMAT(created_time, '%Y-%m-%d'), @num := @num + 1, 1) as row_num,
@created_time := DATE_FORMAT(created_time, '%Y-%m-%d') as axisTime FROM praise_info
order by id desc
) AS temp
WHERE row_num 3;
DROP PROCEDURE IF EXISTS pro_dim_date;
tudou@Gyyx
CREATE PROCEDURE pro_dim_date(IN bdate DATE,IN edate DATE)
BEGIN
DECLARE var DATE DEFAULT bdate;
DECLARE evar DATE DEFAULT DATE_ADD(edate,INTERVAL 1 DAY);
DECLARE bweek DATE;
DECLARE eweek DATE;
WHILE varevar DO
SET bweek = DATE_ADD(DATE_SUB(var,INTERVAL 1 WEEK),INTERVAL 1 DAY);
SET eweek = DATE_SUB(DATE_ADD(var,INTERVAL 1 WEEK),INTERVAL 1 DAY);
INSERT INTO gyyx_report.dim_date
(
`date_id`,
`date_name`,
`date_of_month`,
`year_id`,
`year_name`,
`quarter_id`,
`quarter_name`,
`month_id`,
`month_name`,
`month_of_year_name`,
`month_of_year_id`,
`week_id`,
`week_name`,
`week_of_year_id`,
`week_of_year_name`,
`is_weekend`
)
VALUES
(
DATE_FORMAT(var,'%Y%m%d'),
DATE_FORMAT(var,'%Y-%m-%d'),
DAYOFMONTH(var),
YEAR(var),
CONCAT(YEAR(var),'年'),
QUARTER(var),
CONCAT(QUARTER(var),'季度'),
DATE_FORMAT(var,'%Y%m'),
CONCAT(YEAR(var),'年',MONTH(var),'月'),
CONCAT(MONTH(var),'月'),
MONTH(var),
WEEKDAY(var),
CASE WEEKDAY(var) WHEN 0 THEN '星期一' WHEN 1 THEN '星期二' WHEN 2 THEN '星期三' WHEN 3 THEN '星期四' WHEN 4 THEN '星期五' WHEN 5 THEN '星期六' WHEN 6 THEN '星期日' END,
WEEKOFYEAR(var),
CONCAT('第',WEEKOFYEAR(var),'周(',MONTH(bweek),'月',DAY(bweek),'日~',MONTH(eweek),'月',DAY(eweek),'日'),
CASE WHEN WEEKDAY(var)>4 THEN '是' ELSE '否' END
);
SET var=DATE_ADD(var,INTERVAL 1 DAY);
END WHILE;
END
CREATE TABLE `dim_date` (
nbsp; `date_id` int(11) NOT NULL COMMENT '20110512',
nbsp; `date_name` varchar(16) DEFAULT NULL COMMENT '2011-05-12',
nbsp; `date_of_month` int(11) DEFAULT NULL COMMENT '12',
nbsp; `year_id` int(11) DEFAULT NULL COMMENT '2011',
nbsp; `year_name` varchar(16) DEFAULT NULL COMMENT '2011年',
nbsp; `quarter_id` int(11) DEFAULT NULL COMMENT '2',
nbsp; `quarter_name` varchar(16) DEFAULT NULL COMMENT '2季度',
nbsp; `month_id` int(11) DEFAULT NULL COMMENT '5',
nbsp; `month_name` varchar(16) DEFAULT NULL COMMENT '5月',
nbsp; `month_of_year_name` varchar(16) DEFAULT NULL COMMENT '2011年5月',
nbsp; `month_of_year_id` int(11) DEFAULT NULL COMMENT '201105',
nbsp; `week_id` int(11) DEFAULT NULL,
nbsp; `week_name` varchar(16) DEFAULT NULL,
nbsp; `week_of_year_id` int(11) DEFAULT NULL,
nbsp; `week_of_year_name` varchar(32) DEFAULT NULL,
nbsp; `is_weekend` enum('否','是') DEFAULT NULL COMMENT '是否周末',
nbsp; PRIMARY KEY (`date_id`),
nbsp; KEY `ix_dim_date_date_name` (`date_name`),
nbsp; KEY `ix_dim_date_month_id` (`month_id`),
nbsp; KEY `ix_dim_date_year_id` (`year_id`),
nbsp; KEY `ix_dim_date_quanter_id` (`quarter_id`),
nbsp; KEY `ix_dim_date_week_of_year_id` (`week_of_year_id`,`week_of_year_name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
以上所述是小編給大家介紹的Mysql時間軸數(shù)據(jù) 獲取同一天數(shù)據(jù)的前三條,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!