dreweezy
dreweezy

Reputation: 35

Count number of + and - values based on another column

I am trying to get a simple count of all the negative and positive values of a specific column on my database. I want to be able to count these values based on another column. What would be the best way to go about handling this problem.

enter image description here

Upvotes: 0

Views: 46

Answers (1)

Caius Jard
Caius Jard

Reputation: 74660

Something like this:

SELECT 
  SUM(CASE WHEN column > 0 THEN 1 ELSE 0 END) as count_positive,
  SUM(CASE WHEN column < 0 THEN 1 ELSE 0 END) as count_negative
FROM
  table

You must put the column name, table name, and decide whether 0 is positive, negative or excluded (my choice)

Upvotes: 1

Related Questions