BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

help with sql

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO)
View previous topic :: View next topic  
Author Message
Terry
Guest





PostPosted: Thu Jul 29, 2004 5:05 pm    Post subject: help with sql Reply with quote



using Delphi 6 and MSsql2000

the following sql returns a total

select clocknum, sum(hours) as total
from emphours
where status = 'P'
group by clocknum

The status field has three different values, and I need the totals for all
three. {P, A, D}. Rather than write three selects, is there a way to get
three totals with one select statement?

Thanks


Back to top
Vitali Kalinin
Guest





PostPosted: Thu Jul 29, 2004 5:26 pm    Post subject: Re: help with sql Reply with quote



select status, clocknum, sum(hours) as total
from emphours
group by status, clocknum

"Terry" <cooleyt (AT) woh (DOT) rr.com> сообщил/сообщила в новостях следующее:
news:41092e69 (AT) newsgroups (DOT) borland.com...
Quote:
using Delphi 6 and MSsql2000

the following sql returns a total

select clocknum, sum(hours) as total
from emphours
where status = 'P'
group by clocknum

The status field has three different values, and I need the totals for all
three. {P, A, D}. Rather than write three selects, is there a way to get
three totals with one select statement?

Thanks





Back to top
Terry
Guest





PostPosted: Thu Jul 29, 2004 7:19 pm    Post subject: Re: help with sql Reply with quote



select status, clocknum, sum(hours) as total
from emphours
group by status, clocknum



can this sql be modified to only return sums greater than a given value?


Back to top
Daryl
Guest





PostPosted: Thu Jul 29, 2004 9:25 pm    Post subject: Re: help with sql Reply with quote

Something like...

select status, clocknum, sum(hours) as total
from emphours
HAVING SUM(hours) > 8
group by status, clocknum

The HAVING clause ia applied to each of the groups, in this case each
grouping of status, clocknum.


"Terry" <cooleyt (AT) woh (DOT) rr.com> wrote

Quote:
select status, clocknum, sum(hours) as total
from emphours
group by status, clocknum



can this sql be modified to only return sums greater than a given value?





Back to top
afm
Guest





PostPosted: Thu Jul 29, 2004 10:51 pm    Post subject: Re: help with sql Reply with quote

Not being an expert at sql, I build queries in MS Access switch to sql view
and copy and past the sql statements. This was the result.

SELECT emphours.ClockNum, emphours.Status, Sum(emphours.Hours) AS Total
FROM emphours
GROUP BY emphours.ClockNum, emphours.Status;

Appears to agree with the other suggestions.



"Daryl" <developeracc (AT) hotmail (DOT) com> wrote

Quote:
Something like...

select status, clocknum, sum(hours) as total
from emphours
HAVING SUM(hours) > 8
group by status, clocknum

The HAVING clause ia applied to each of the groups, in this case each
grouping of status, clocknum.


"Terry" <cooleyt (AT) woh (DOT) rr.com> wrote in message
news:41094db4$3 (AT) newsgroups (DOT) borland.com...
select status, clocknum, sum(hours) as total
from emphours
group by status, clocknum



can this sql be modified to only return sums greater than a given value?







Back to top
Daryl
Guest





PostPosted: Fri Jul 30, 2004 8:00 am    Post subject: Re: help with sql Reply with quote

Sorry I shoud have shown the HAVING clause after the GROUP BY clause.

select status, clocknum, sum(hours) as total
from emphours
group by status, clocknum
HAVING SUM(hours) > 8


"Daryl" <developeracc (AT) hotmail (DOT) com> wrote in message


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.