Sora
Sora

Reputation: 2551

Get specific records from sql database when using aggregate function as Sum

I am using this query to filter some record from my sql database:

select Distinct x, SUM(y)AS Total 
from T  
where j=2 
group by x

The returned values are as follows:

2585   -1
1804   -8
1781   900.56
1712   -6
1612   -2
2591   66

Is there a way to filter the result where Sum(y) > 0?

Upvotes: 0

Views: 33

Answers (1)

TheGameiswar
TheGameiswar

Reputation: 28930

Use Having.Where clause acts on individual records,Having acts on Groups

select Distinct x,
 SUM(y)AS Total from T  
where j=2 group by x
having sum(y)>0

Upvotes: 2

Related Questions