Monday, February 27, 2012

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.try this

select company, sum(amount)
from table
where (the conditions you like)
group by company
having sum(amount) > 5000|||Select
Company,
Sum(Amount) as CompanyTotal

From
Table

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

Group by
Company|||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.

No comments:

Post a Comment