sql - Sum sql问题 - 里面的两列是连接的
问题描述
请问,是否可以通过一个查询返回此结果(来自下表)?
CountId = 4,SumTime = 60,SumServices = 11(问题在于与服务连接的 Sumtime)
ID Date Time Services
6267 2018-07-10 10 1
6846 2018-08-21 5 4
7129 2018-09-11 5 4
7224 2018-09-18 5 2
解决方案
调用 Sum 时只需将列相乘
SELECT COUNT(*) AS CountId, SUM(time*services) AS SumTime, SUM(services) AS SumServices
FROM table
推荐阅读
- php - 如何从 php 中的远程 XML 中的短语中获取数据?
- python-2.x - 警告:无法解析“python2-audit”,“selinux-python2”的依赖项 - Arch linux
- uicolor - 如何在 iOS13 中结合 SearchController 更改 NavController 的 Backbutton-tintColor
- machine-learning - 用于新奇检测的一类 SVM 和隔离森林
- python - 我怎样才能提高速度
- javascript - 如何使用用户数组和 axio get 在反应 js 中调用复选框中的 onchange 函数?
- r - 如何将 princomp 结果打印、写入或导出到 csv 文件
- java - 想知道确切位置的谷歌地图弹出窗口或片段
- .net-core - SecurityRequirementsOperationFilter 不起作用
- php - 在我的 Woocommerce 帐户订单表中显示产品描述