Kuntal Parbat
Kuntal Parbat

Reputation: 159

Get count total time for particular task and particular user group by Task id

I have a MySQL table where time, task, user data saving through PHP script. I want to make a MySQL Query where I want to get:

 User ID    Date    Project   id    Task id Count
   1    14-11-2017  17        3     5:20:00
   1    14-11-2017  17        1     00:50:20

Project Date and user id will be common because those are data are querying Item.

SELECT `emp_id`,
   `count_date`,
   `project_id`,
   `task_id`
FROM `task_counter`
WHERE `emp_id` = "'.$userid.'" && `count_date` = "'.$date.'"

This query returning all the value for the user and the given date.

if I use MySQL Group query then how do I put "where $userid = "This" && $date = "This".

My Sample table is this: sample table

Please let me know if any more details require.

Please guide me, Thanks.

Upvotes: 0

Views: 188

Answers (1)

Jacob Mulquin
Jacob Mulquin

Reputation: 3608

You need to group by the task_id and then do some strange SQL stuff to get the sum of seconds then convert back to time.

SELECT 
    emp_id, count_date, project_id, task_id, 
    SEC_TO_TIME(SUM(TIME_TO_SEC(count_time))) as 'total_time'
FROM task_counter
WHERE emp_id = '1'
AND count_date = '2017-11-14'
GROUP BY task_id;

SQLFiddle

Upvotes: 1

Related Questions