OctoberWind
07-28-2009, 11:37 AM
I think this can be done with one query, but it doesn't seem to want to work for me.
Columns needed:
toolbox_id (int)
category_id (int)
vote_rank (int)
(I'm going to need more, but I should be able to figure out the inner joins once the base query is fixed.)
What I need
A list of each toolbox_id and the count of how many vote_ranks, ordered preferably by the count(vote_rank)
as such:
toolbox_id category_id vote_rank count(vote_rank)
1 1 1 10
1 1 3 8
1 1 2 6
2 1 1 12
2 1 2 7
2 1 3 2
ect...
toolbox_id will have multiple records, and vote_rank will be either 1, 2 or 3. My plan is to sort 'where category_id = X' in the end.
What i've tried
select toolbox_id, vote_rank, count(vote_rank) from pten_votes where category_id = 1 order by vote_rank
What that gives me (one row)
toolbox_id vote_rank count( vote_rank )
2 3 12
Which actually isn't what i think it should be, because
select * from pten_votes where toolbox_id=2 and vote_rank=3
gives me
toolbox_id category_id vote_rank
2 1 3
2 1 3
2 1 3
I'm sure I'm missing something simple...
Columns needed:
toolbox_id (int)
category_id (int)
vote_rank (int)
(I'm going to need more, but I should be able to figure out the inner joins once the base query is fixed.)
What I need
A list of each toolbox_id and the count of how many vote_ranks, ordered preferably by the count(vote_rank)
as such:
toolbox_id category_id vote_rank count(vote_rank)
1 1 1 10
1 1 3 8
1 1 2 6
2 1 1 12
2 1 2 7
2 1 3 2
ect...
toolbox_id will have multiple records, and vote_rank will be either 1, 2 or 3. My plan is to sort 'where category_id = X' in the end.
What i've tried
select toolbox_id, vote_rank, count(vote_rank) from pten_votes where category_id = 1 order by vote_rank
What that gives me (one row)
toolbox_id vote_rank count( vote_rank )
2 3 12
Which actually isn't what i think it should be, because
select * from pten_votes where toolbox_id=2 and vote_rank=3
gives me
toolbox_id category_id vote_rank
2 1 3
2 1 3
2 1 3
I'm sure I'm missing something simple...