Greetings.
I have a MySQL table Time_worked with a column Time_worked as follows:
| TIME_WORKED | varchar(500) | YES | | NULL | |
I am trying to find the sum(Time_Worked) in a Spring application using the JDBCTemplate as follows:
String totalEffortQuery = "SELECT sum(TIME_WORKED) FROM time_worked WHERE USER = ? and UPDATED>= now() - INTERVAL 1 DAY";
Long totalEffortSeconds = jdbcTemplate.queryForObject(
totalEffortQuery, new Object[] { assignedTo }, Long.class);
But the totalEffortSeconds always has a NULL value.
But when I run this query directly in the database as follows it returns results:
SELECT sum(TIME_WORKED) FROM time_worked WHERE USER = 'Vishwanath Krishna Bhat' and UPDATED>= now() - INTERVAL 1 DAY;
+------------------+
| sum(TIME_WORKED) |
+------------------+
| 43200 |
+------------------+
1 row in set (0.02 sec)
I read it somewhere that you cannot use SUM on a non numeric value, but it does work when i use it directly in the database.
Kindly note that I am passing correct USER value in my Java code and that is not the issue.
Can someone please help me out on this ?
Regards, Vishwa