Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
SELECT avg(duration) as average FROM login;
login
持续时间的数据类型是“时间”,因此我的值是:00:00:14、00:20:23 等
我执行它给我的查询:2725.78947368421
那是什么?我想要时间格式,mysql可以按时平均吗?
试试这个:
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