 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Terry Guest
|
Posted: Thu Jul 29, 2004 5:05 pm Post subject: help with sql |
|
|
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
|
Posted: Thu Jul 29, 2004 5:26 pm Post subject: Re: help with sql |
|
|
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
|
Posted: Thu Jul 29, 2004 7:19 pm Post subject: Re: help with sql |
|
|
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
|
Posted: Thu Jul 29, 2004 9:25 pm Post subject: Re: help with sql |
|
|
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
|
Posted: Thu Jul 29, 2004 10:51 pm Post subject: Re: help with sql |
|
|
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
|
Posted: Fri Jul 30, 2004 8:00 am Post subject: Re: help with sql |
|
|
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 |
|
 |
|
|
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
|
|