我的一个表中有两列名为TIME_OUT和TIME_IN。这些都是十进制值。我基本上想要总结这些列的差异。我有下面的查询输出差异没有问题,但我想然后总结差异:
SELECT (TIME_IN-TIME_OUT) AS DIFF FROM TABLE_timelogs WHERE YEAR(LOG_DATE) = YEAR(NOW());
+------+
| DIFF |
+------+
| 10.0 |
| 4.0 |
| 3.0 |
+------+
有没有办法将SUM集成到查询中,以便最终输出为17.0?提前谢谢!
答案 0 :(得分:8)
将SUM添加到查询中,以便查询显示:
SELECT SUM(TIME_IN-TIME_OUT) AS DIFF
FROM TABLE_timelogs
WHERE YEAR(LOG_DATE) = YEAR(NOW());
这会添加列'差异'
的内容