0

I have the following table. Now I want to count the amount of each value in this table.

value count
1 1
-1 1
2 1
3 1

-1 and 1 should be seen as 1, so the output should be

value count
1 2
2 1
3 1

Does someone know a quick fix?

4
  • GROUP BY the absolute value? Commented Jan 5, 2022 at 15:54
  • You can use SUM(ABS(column_name)). Already answered here. Commented Jan 5, 2022 at 15:56
  • You can use SUM(ABS(column_name)) as mentioned here Commented Jan 5, 2022 at 15:59
  • Which dbms are you using? Commented Jan 5, 2022 at 16:18

1 Answer 1

1

Grouping by value, and making such values the absolute value so you ignore the negative sign:

SELECT
ABS(VALUE) VALUE, COUNT() COUNT
FROM
table
GROUP BY 
ABS(VALUE)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.