对日期时间进行加减法运算
(ADDDATE()和SUBDATE()是DATE_ADD()和DATE_SUB()的同义词,也可以用运算符 和-而不是函数
date是一个DATETIME或DATE值,expr对date进行加减法的一个表达式字符串type指明表达式expr应该如何被解释
[type值 含义 期望的expr格式]:
SECOND 秒 SECONDS
MINUTE 分钟 MINUTES
HOUR 时间 HOURS
DAY 天 DAYS
MONTH 月 MONTHS
YEAR 年 YEARS
MINUTE_SECOND 分钟和秒 "MINUTES:SECONDS"
HOUR_MINUTE 小时和分钟 "HOURS:MINUTES"
DAY_HOUR 天和小时 "DAYS HOURS"
YEAR_MONTH 年和月 "YEARS-MONTHS"
HOUR_SECOND 小时, 分钟, "HOURS:MINUTES:SECONDS"
DAY_MINUTE 天, 小时, 分钟 "DAYS HOURS:MINUTES"
DAY_SECOND 天, 小时, 分钟, 秒 "DAYS HOURS:MINUTES:SECONDS"
expr中允许任何标点做分隔符,如果所有是DATE值时结果是一个DATE值,否则结果是一个DATETIME值)
如果type关键词不完整,则MySQL从右端取值,DAY_SECOND因为缺少小时分钟等于MINUTE_SECOND)
如果增加MONTH、YEAR_MONTH或YEAR,天数大于结果月份的最大天数则使用最大天数)
mysql>SELECT "1997-12-31 23:59:59" INTERVAL 1 SECOND
->1998-01-01 00:00:00
mysql>SELECT INTERVAL 1 DAY "1997-12-31"
->1998-01-01
mysql>SELECT "1998-01-01" - INTERVAL 1 SECOND
->1997-12-31 23:59:59
mysql>SELECT DATE_ADD("1997-12-31 23:59:59",INTERVAL 1 SECOND)
->1998-01-01 00:00:00
mysql>SELECT DATE_ADD("1997-12-31 23:59:59",INTERVAL 1 DAY)
->1998-01-01 23:59:59
mysql>SELECT DATE_ADD("1997-12-31 23:59:59",INTERVAL "1:1" MINUTE_SECOND)
->1998-01-01 00:01:00
mysql>SELECT DATE_SUB("1998-01-01 00:00:00",INTERVAL "1 1:1:1" DAY_SECOND)
->1997-12-30 22:58:59
mysql>SELECT DATE_ADD("1998-01-01 00:00:00", INTERVAL "-1 10" DAY_HOUR)
->1997-12-30 14:00:00
mysql>SELECT DATE_SUB("1998-01-02", INTERVAL 31 DAY)
->1997-12-02
mysql>SELECT EXTRACT(YEAR FROM "1999-07-02")
->1999
mysql>SELECT EXTRACT(YEAR_MONTH FROM "1999-07-02 01:02:03")
->199907
mysql>SELECT EXTRACT(DAY_MINUTE FROM "1999-07-02 01:02:03")
->20102
TO_DAYS(date)
返回日期date是西元0年至今多少天(不计算1582年以前)
mysql>select TO_DAYS(950501)
->728779
mysql>select TO_DAYS('1997-10-07')
->729669
FROM_DAYS(N)
给出西元0年至今多少天返回DATE值(不计算1582年以前)
mysql>select FROM_DAYS(729669)
->'1997-10-07'
本文来自CSDN博客,转载请标明出处:http://www.cnblogs.com/zeroone/archive/2010/05/05/1727659.html
以下是创建一张测试表TEST并且按照时间CREATE_TIME创建RANGE分区,并使用ID创建hash分区,组成复合分区。CREATE TABLE TEST (
CREATE_TIME DATETIME DEFAULT NULL, ID BIGINT(15) DEFAULT NULL
) ENGINE=INNODB DEFAULT CHARSET=utf8
PARTITION BY RANGE(TO_DAYS(CREATE_TIME)) PARTITIONS 7 SUBPARTITION BY HASH(ID) SUBPARTITIONS 16
(PARTITION P1710 VALUES LESS THAN (TO_DAYS ('2017-10-01'))
(SUBPARTITION P1710sp0 ,SUBPARTITION P1710sp1 ,
SUBPARTITION P1710sp2 ,SUBPARTITION P1710sp3 ,
SUBPARTITION P1710sp4 ,SUBPARTITION P1710sp5 ,
SUBPARTITION P1710sp6 ,SUBPARTITION P1710sp7 ,
SUBPARTITION P1710sp8 ,SUBPARTITION P1710sp9 ,
SUBPARTITION P1710sp10 ,SUBPARTITION P1710sp11 ,
SUBPARTITION P1710sp12 ,SUBPARTITION P1710sp13 ,
SUBPARTITION P1710sp14 ,SUBPARTITION P1710sp15 ),
PARTITION P1711 VALUES LESS THAN (TO_DAYS ('2017-11-01'))
(SUBPARTITION P1711sp0 ,SUBPARTITION P1711sp1 ,
SUBPARTITION P1711sp2 , SUBPARTITION P1711sp3 ,
SUBPARTITION P1711sp4 , SUBPARTITION P1711sp5 ,
SUBPARTITION P1711sp6 , SUBPARTITION P1711sp7 ,
SUBPARTITION P1711sp8 , SUBPARTITION P1711sp9 ,
SUBPARTITION P1711sp10 , SUBPARTITION P1711sp11 ,
SUBPARTITION P1711sp12 , SUBPARTITION P1711sp13 ,
SUBPARTITION P1711sp14 , SUBPARTITION P1711sp15 ),
select 时间,max(case when devinx=1 and `desc`='温度' then data else 0 end),
max(case when devinx=1 and `desc`='湿度' then data else 0 end),
max(case when devinx=2 and `desc`='温度' then data else 0 end),
max(case when devinx=2 and `desc`='湿度' then data else 0 end),
max(case when devinx=3 and `desc`='温度' then data else 0 end),
max(case when devinx=3 and `desc`='湿度' then data else 0 end)
from 表名
group by 时间
看看是这样吗?
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)