Mysql 平均时间列?
SELECT avg( duration ) as average FROM login
;
SELECT avg( duration ) as average FROM login
;
持续时间的数据类型是时间",因此我的值是:00:00:14、00:20:23等
The datatype for duration is "time", thus my value is like: 00:00:14, 00:20:23 etc
我执行它给我的查询:2725.78947368421
I execute the query it gives me: 2725.78947368421
那是什么?我要时间格式的,mysql可以按时间做平均吗??
What is that? I want in time format, can mysql do the average on time??
推荐答案
试试这个:
SELECT SEC_TO_TIME(AVG(TIME_TO_SEC(`login`))) FROM Table1;
测试数据:
CREATE TABLE `login` (duration TIME NOT NULL);
INSERT INTO `login` (duration) VALUES
('00:00:20'),
('00:01:10'),
('00:20:15'),
('00:06:50');
结果:
00:07:09
相关文章