一旦我確定如何溝通我想要的內容,我會用適當的名稱修改問題。我可以從sql中的選擇中獲得比率嗎?
我有一個名爲batch_log的表,其中有人開始和停止批處理工作。每個條目看起來是這樣的:
"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"
我真正想要做的是爲一個特定的人選擇他們有多久相比,總時間爲批次追蹤,以便我可以給他們的信貸那麼多的預計時間。有沒有辦法在SQL中做到這一點?
EDIT [落得這樣做如下:]
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
你的意思是要計算TIME_ELAPSED /(END_TIME - START_TIME)是什麼?如果你這樣做,那麼只要你知道從另一個日期中減去一個日期就會給你一個以天爲單位的持續時間,這是相對簡單的。 –
不,他想要計算(time_elapsed_on_batch_id_for_user id/total_time_elapsed_for_batch_id)。注意''time_elapsed' =='(end_time - start_time)' – anothershrubery