1

I have a table with 3 columns: key, status and rank.
status contains numbers and rank contains t or f.
key is auto numbered and irrelevant here.

my goal is to count how many in each status are t and how many false for example:

if my data is (key, status, rank)

1 10 f
2 10 t
3 10 t
4 11 t

then result will be : (status, rank, count value)

10 f 1
10 t 2
11 t 1

how do i do that?

1

This is a simple group by query.

select status, 
       rank,
       count(*) as cnt
from the_table
group by status, rank
order by status, rank;
  • where do you take under consideration the rank? it seems like you just counting statuses regardless of the rank. – someone45 Jun 1 '15 at 8:38
  • ok based on your answer this is the correct solution: select status, rank, count(*) as cnt from the_table group by status, rank order by status; – someone45 Jun 1 '15 at 8:41
  • @someone45: ah, sorry. I mixed up the columns. – a_horse_with_no_name Jun 1 '15 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.