2012-09-11 63 views
-3

全部,如何分組記錄和總計

我在表中有以下記錄。根據timesheetID,jobId,Startime,我需要每天在每項工作上累計時間花費。有人可以建議最好的方法嗎?

jobID  startTime     endTime    totalTime    timesheetID 
4   2012-09-10     2012-09-10   1.466667    12300 
4   2012-09-10     2012-09-10   1.466667    12300 
4   2012-09-11     2012-09-11   5.116667    12300 
12  2012-09-10     2012-09-10   1.466667    12300 
12  2012-09-11     2012-09-11    0.3    12300 
4   2012-09-10     2012-09-10   1.433333    12400 
12  2012-09-11     2012-09-11   4.966667    12400 
13  2012-09-10     2012-09-10     2.2    12400 
12  2012-09-11     2012-09-11   0.3333333    12400 
4   2012-09-11     2012-09-11    0.4833333   12400 
4   2012-09-10     2012-09-10    2.016667   12600 
13  2012-09-11     2012-09-11    4.866667   12600
+4

[你試過了什麼?](http://www.whathaveyoutried.com) – Kermit

+2

這是最基本的SUM聚合函數。張貼你已經嘗試過的東西。 – Randy

回答

1

你應該使用聚合函數SUM()GROUP BY

select timesheetid, jobid, starttime, sum(totaltime) TotTime 
from yourtable 
group by timesheetid, jobid, starttime 

看到SQL Fiddle with demo

+0

我知道這是最基本的,我無法得到它的工作。 thans。 – user14750