Mysql Average on time column?

China☆狼群 提交于 2019-11-29 15:55:09

问题


SELECT avg( duration ) as average FROM login;

The datatype for duration is "time", thus my value is like: 00:00:14, 00:20:23 etc

I execute the query it gives me: 2725.78947368421

What is that? I want in time format, can mysql do the average on time??


回答1:


Try this:

SELECT SEC_TO_TIME(AVG(TIME_TO_SEC(`login`))) FROM Table1;

Test data:

CREATE TABLE `login` (duration TIME NOT NULL);
INSERT INTO `login` (duration) VALUES
('00:00:20'),
('00:01:10'),
('00:20:15'),
('00:06:50');

Result:

00:07:09


来源:https://stackoverflow.com/questions/2217139/mysql-average-on-time-column

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!