Question

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!

Était-ce utile?

La solution

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'.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top