문제

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!

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top