8

I have two columns in one of my tables called TIME_OUT and TIME_IN. These are both decimal values. I basically want to sum the difference of these columns. I have the query below that outputs the difference with no issue, but I'd like to then SUM the difference:

SELECT (TIME_IN-TIME_OUT) AS DIFF FROM TABLE_timelogs WHERE YEAR(LOG_DATE) = YEAR(NOW());

+------+
| DIFF | 
+------+
| 10.0 |
|  4.0 |
|  3.0 |
+------+

Is there a way to integrate SUM into the query so that the ultimate output is 17.0? Thank you in advance!

Jason
  • 1,105
  • 3
  • 16
  • 30

1 Answers1

12

Add SUM to your query so the query reads:

SELECT SUM(TIME_IN-TIME_OUT) AS DIFF 
FROM TABLE_timelogs 
WHERE YEAR(LOG_DATE) = YEAR(NOW());

This adds the contents of the column 'diff'.

Hank G
  • 379
  • 3
  • 16
  • 2
    Wow - that was easy and did the trick! Thank you for the help!! – Jason Apr 01 '14 at 20:40
  • I have posted a [question](https://stackoverflow.com/questions/62608035/mysql-show-sum-of-difference-of-two-values) related to it can you please see it? – Moeez Jun 27 '20 at 09:18