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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 grouping help

Author  Topic 

ronin2307
Posting Yak Master

126 Posts

Posted - 2006-07-26 : 09:12:33
Hi I have the following query:

select ladetail.fjobno,	datediff(minute,ladetail.fsdatetime,ladetail.fedatetime) as mins,ladetail.fpro_id
from ladetail
where 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 same

any 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_id
from ladetail
where ladetail.fjobno like '12761%' and ladetail.fpro_id <> 'ENG'
and ladetail.fempno = '295'
group by ladetail.fjobno,ladetail.fpro_id
order by ladetail.fjobno asc


Chirag
Go to Top of Page

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
Go to Top of Page

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
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-07-27 : 12:02:14
Also Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -