Mysql multiple row count?

Posted by Steven on Stack Overflow See other posts from Stack Overflow or by Steven
Published on 2011-01-04T00:42:59Z Indexed on 2011/01/04 0:54 UTC
Read the original article Hit count: 137

Filed under:
|
|

Hello,

I have a database full of rows like

id,action,date
2,2,2010-03-01
3,2,2010-03-01
4,3,2010-03-01
5,3,2010-03-01
6,4,2010-02-01
7,4,2010-02-01

And I want to select all the count all the 2's and all the 3's and all the 4's. But I don't want to have to do 3 different SELECT COUNT() commands, is there a way to do this in a single command?

Note, I want to display this as something like

  • Action 2 = 2
  • Action 3 = 2
  • Action 4 = 2
  • (etc etc).

And I will also need to specific a date (so it only counts all the 2,3,4,etc for dates between 2010-02-03 and 2010-03-01 for example)

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql