I will revise the question with an appropriate name once I’m certain how to communicate what I want.
I have a table called batch_log where people start and stop the work on a batch. Each entry looks like this:
"id";"batch_id";"userid";"start_time";"end_time";"time_elapsed"
"99980";"cd9e4c9e-d8bb-4983-64f4-4e777b451b93";"phastie";"2011-09-22 08:54:34";"2011-09-22 10:07:07";"01:12:33"
What I really want to do is for a particular person select how long they have tracked compared to the total time for that batch so that I can give them credit for that much of the estimated time. Is there a way to do this in sql?
EDIT[Ended up doing the following:]
SELECT user_time_by_batch.batch_id, userid, user_time_by_batch / total_time_by_batch FROM
(
SELECT SUM(time_elapsed) user_time_by_batch, userid, batch_id
FROM batch_log
Where start_time between "2011-08-01" and now()
and end_time is not null and time_elapsed BETWEEN "00:00:00" AND "10:00:00"
and batch_id not in ("-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9", "-10", "-11", "-12", "-13")
GROUP BY batch_id, userid
) user_time_by_batch
INNER JOIN
(
SELECT SUM(time_elapsed) total_time_by_batch, batch_id
FROM batch_log
Where start_time between "2011-08-01" and now()
and end_time is not null and time_elapsed BETWEEN "00:00:00" AND "10:00:00"
and batch_id not in ("-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9", "-10", "-11", "-12", "-13")
GROUP BY batch_id
) total_time_by_batch
ON user_time_by_batch.batch_id = total_time_by_batch.batch_id
This should give you what you need