Duy Huynh
Duy Huynh

Reputation: 11

SQL return sum of a column

TYPE  VALUE
A       4
A       5
A       6
B       1
B       1

I need to check which type has sum(value) < 3, but i can't find a way to return sum(value) of a specific type for the comparison operator.

Upvotes: 1

Views: 38

Answers (1)

Mureinik
Mureinik

Reputation: 311338

Just group by the type and apply a having clause:

SELECT   type
FROM     mytbale
GROUP BY type
HAVING   SUM(value) < 3

Upvotes: 3

Related Questions