查看:1776|回复:0
mysql 5.5 根据日期分区 sql 分享发表时间:2014-07-16 16:19:28

tech

0分享0主题0帖子

学徒一级

(初出茅庐)

最近用mysql 进行分区,分享下代码

CREATE TABLE part_date (
  c1 int default NULL,
  c2 varchar(30) default NULL,
  c3 date default NULL
) engine=myisam
  
partition by range (to_days(c3)) (
 PARTITION p0 VALUES LESS THAN (to_days('1995-01-01')),
 PARTITION p1 VALUES LESS THAN (to_days('1996-01-01')) ,
 PARTITION p2 VALUES LESS THAN (to_days('1997-01-01')) ,
 PARTITION p3 VALUES LESS THAN (to_days('1998-01-01')) ,
 PARTITION p4 VALUES LESS THAN (to_days('1999-01-01')) ,
 PARTITION p5 VALUES LESS THAN (to_days('2000-01-01')) ,
 PARTITION p6 VALUES LESS THAN (to_days('2001-01-01')) ,
 PARTITION p7 VALUES LESS THAN (to_days('2002-01-01')) ,
 PARTITION p8 VALUES LESS THAN (to_days('2003-01-01')) ,
 PARTITION p9 VALUES LESS THAN (to_days('2004-01-01')) ,
 PARTITION p10 VALUES LESS THAN (to_days('2010-01-01')),
 PARTITION px VALUES LESS THAN MAXVALUE
);


您需要登录以后才可以回帖    登录|注册