Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

This is a simple group by query.

select status, 
       rank,
       count(*) as cnt
from the_table
group by status, rank
order by status, rank;
share|improve this answer
    
where do you take under consideration the rank? it seems like you just counting statuses regardless of the rank. –  someone45 Jun 1 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 at 8:41
    
@someone45: ah, sorry. I mixed up the columns. –  a_horse_with_no_name Jun 1 at 8:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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