1

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)

4 Answers 4

4
   SELECT action
        , Count(*)
     FROM Table
    WHERE date BETWEEN startDate AND EndDate
 GROUP BY Action
Sign up to request clarification or add additional context in comments.

Comments

0
SELECT COUNT(*) FROM table GROUP BY action

Comments

0

You can GROUP BY action your query. Also you could combine it with a WHERE id IN (2,3,4) to only get the rows for those ids.

Comments

0

SELECT COUNT(*) as count FROM tableA GROUP BY columnA WHERE DATE BETWEEN dateFrom AND dateTO

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.