If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > help!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-08-04, 02:20
put_put put_put is offline
Registered User
 
Join Date: Nov 2003
Posts: 5
Red face help!

date company amount
01/01 ABS 2000
10/01 KB 1500
02/03 ABS 4000
02/04 LB 3000
04/05 KB 3000
05/06 LB 7000



i need help to write a SQL statement which can output companies with a total amount over 5000 for the period 01/01 to 05/06.
Reply With Quote
  #2 (permalink)  
Old 07-08-04, 03:58
iaguigon iaguigon is offline
Registered User
 
Join Date: May 2004
Location: Barcelona, Spain
Posts: 54
try this

select company, sum(amount)
from table
where (the conditions you like)
group by company
having sum(amount) > 5000
Reply With Quote
  #3 (permalink)  
Old 07-08-04, 14:06
AceOmega AceOmega is offline
Registered User
 
Join Date: Apr 2004
Location: Arizona
Posts: 49
Another way

Select
Company,
Sum(Amount) as CompanyTotal

From
Table

Where
(CompanyTotal > 5000)
AND
( Date > 01/01
and
Date < 05/06)

Group by
Company

Last edited by AceOmega; 07-08-04 at 14:14.
Reply With Quote
  #4 (permalink)  
Old 07-08-04, 19:03
r123456 r123456 is offline
Registered User
 
Join Date: Sep 2003
Location: The extremely Royal borough of Kensington, London
Posts: 778
Please note that 'Having sum(amount) > x' is not equal to 'where amount > x'. Having is a post group function while where is a pre function.
__________________
Bessie Braddock: Winston, you are drunk!
Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On