drop table if exists `shop_diancai`;
create table `shop_diancai` (
`id` bigint(20) not null auto_increment comment '點餐id,由程式生成',
`orderid` bigint(20) not null comment '訂單id',
`diancaino` varchar(50) not null comment '點餐編號',
`vegetableid` bigint(20) not null comment '菜品id',
`num` int(1) not null default '0' comment '數量',
`price` int(6) not null comment '**',
`type` int(1) not null default '1' comment '1點菜,2加菜',
`isdel` int(1) not null default '0' comment '1未刪除 0刪除',
`createtime` datetime not null comment '點餐時間',
`confirmed` int(1) not null default '0' comment '0未確認,1已確認',
`adddish` int(1) not null default '0' comment '與點菜無關加菜次數',
`confirmtime` datetime null comment '修改時間',
primary key (`id`, `createtime`)
) engine=myisam auto_increment=1 default charset=utf8 comment='點餐表'
partition by range (year(createtime)) (
partition p0 values less than (2017) ,
partition p1 values less than (2018) ,
partition p2 values less than (2019) ,
partition p3 values less than (2020) ,
partition p4 values less than (2021) ,
partition p5 values less than (2022) ,
partition p6 values less than (2023) ,
partition p7 values less than (2024) ,
partition p8 values less than (2030) ,
partition p9 values less than (maxvalue) );
create procedure load_shop_diancai()
begin
declare v int default 0;
while v < 8000000
doinsert into shop_diancai (orderid,diancaino,vegetableid,price,createtime)
values (1,'diancaino',1,1.00,adddate('2017-01-01',(rand(v)*36520) mod 3652));
set v = v + 1;
end while;
endcall load_shop_diancai();
select count(*) from shop_diancai where createtime > date '2017-04-01' and createtime < date '2020-12-31';
mysql 日期字串互轉
字串轉日期 select str to date 2008 4 2 15 3 28 y m d h i s select str to date 2008 08 09 08 9 30 y m d h i s 日期轉字串 select date format now y m d 時間戳轉日期 sele...
Mysql 字串日期互轉
時間轉字串 date format 日期,格式字串 select date format now y m d h i s now 為當期時間 結果 2019 08 20 20 40 08 select str to date 2019 08 20 20 40 08 y m d h i 結果 2019...
MySQL按字串hash分割槽 mysql分割槽理論
檢視mysql安裝的引擎 mysql show engines 檢視mysql安裝的外掛程式 這裡用於檢視當前mysql是否支援partition mysql show plugins 不同分割槽對比 分割槽型別 優點 缺點 共性 range 適合與日期型別,支援復合分割槽 有限的分割槽 一般只針對...