给定这样的数据集...
CREATE TABLE totolog
(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY
,dt DATETIME NOT NULL
,data VARCHAR(20) NOT NULL
);
INSERT INTO totolog VALUES
(1 ,'2012-12-01 06:01:01','hi john'),
(2 ,'2013-01-01 06:04:23','hi bob'),
(3 ,'2013-02-01 07:17:36','hi alex'),
(4 ,'2013-03-28 14:49:41','hi all');
我想你会想要这样的东西......
SELECT FROM_UNIXTIME(AVG(UNIX_TIMESTAMP(dt)))x FROM totolog;
+---------------------+
| x |
+---------------------+
| 2013-01-22 20:33:10 |
+---------------------+
1 row in set (0.00 sec)
...或这个...
SELECT FROM_UNIXTIME((MAX(UNIX_TIMESTAMP(dt))+MIN(UNIX_TIMESTAMP(dt)))/2)x
FROM totolog;
+---------------------+
| x |
+---------------------+
| 2013-01-28 22:25:21 |
+---------------------+
1 row in set (0.00 sec)