Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
select ladetail.fjobno, datediff(minute,ladetail.fsdatetime,ladetail.fedatetime) as mins,ladetail.fpro_idfrom ladetailwhere ladetail.fjobno like '12761%' and ladetail.fpro_id <> 'ENG' and ladetail.fempno = '295'order by ladetail.fjobno asc
and this is what I get as a result:12761-0007 690 MAFAB 12761-0010 44 MAFAB 12761-0010 257 MAFAB 12761-0010 283 MAFAB 12761-0010 660 MAFAB what I would like to do is group this by the job number with all the minutes being summed up. I tried to use group by, but that didnt get me anywhere since I have to use ALL colums in the group by statement and then the result is the sameany advice will be appreciated.Thanx
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts
Posted - 2006-07-26 : 09:16:11
Somthing like this
select ladetail.fjobno, Sum(datediff(minute,ladetail.fsdatetime,ladetail.fedatetime)) as mins,ladetail.fpro_idfrom ladetailwhere ladetail.fjobno like '12761%' and ladetail.fpro_id <> 'ENG' and ladetail.fempno = '295'group by ladetail.fjobno,ladetail.fpro_idorder by ladetail.fjobno asc
Chirag
ronin2307
Posting Yak Master
126 Posts
Posted - 2006-07-26 : 09:21:11
very much so...first off, thank you very much...was I mistaken to assume that group by sums things up automatically??? I could have sworn that in the past I have used only group by and it would sum the entries up... maybe I am wrong...thanx anyway
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts
Posted - 2006-07-26 : 09:46:32
Just read about Group by on Book online, it will help you to understand how Group by works. :) Chirag