php - 如何将从sql查询返回的平均时间转换为分钟
问题描述
我正在运行以下查询
SELECT SEC_TO_TIME(AVG(TIME_TO_SEC(Response_Time))) as avg_time
FROM Case_report
where Reporting_Time between "'.$fromdate.'" and "'.$todate.'"
and Police_Circle="Sadar"
并从 sql 中获得正确的结果为“ 00:19:35.6000 ”
我需要在总分钟数内得到结果 像 20
解决方案
在这部分 SQL 中,您将总秒数转换为时间,这就是您将输出作为时间的原因:
SEC_TO_TIME(AVG(TIME_TO_SEC(Response_Time)))
无需将结果转换回时间,只需将秒除以 60 并将数字四舍五入即可获得总分钟数:
ROUND(AVG(TIME_TO_SEC(Response_Time)) / 60)
在您的原始 SQL 语句中:
SELECT ROUND(AVG(TIME_TO_SEC(Response_Time)) / 60) AS avg_time
FROM Case_report
where Reporting_Time between "'.$fromdate.'" and "'.$todate.'"
and Police_Circle="Sadar"
推荐阅读
- c# - What is the difference between Oracle mysqld.data.dll and MariaDB mysql.data.dll for c#?
- javascript - 处理 js 中的请求竞争的最佳实践是什么?
- duplicates - 带有扩展浏览器窗口的 JFreeChart 重复日期
- apostrophe-cms - 如何访问保存在撇号小部件中的数据?
- android - 按钮 onClick Force 关闭 Android 4.1 设备上的应用程序
- blueprism - 如何在 Blue Prism 中使用 dll 或使用 app.config 文件设置 dll
- xml - 多个子元素的 XSLT 转换嵌套循环
- ios - Xcode 找不到已安装的应用程序
- c# - 限制映射到现有目标对象
- javascript - 古腾堡
返回 ReactJS '元素类型无效'