Counting multiple rows in MySQL in one query

Posted by diggersworld on Stack Overflow See other posts from Stack Overflow or by diggersworld
Published on 2010-06-02T11:38:11Z Indexed on 2010/06/02 11:44 UTC
Read the original article Hit count: 127

Filed under:
|

I currently have a table which stores a load of statistics such as views, downloads, purchases etc. for a multiple number of items. To get a single operation count on each item I can use the following query:

SELECT , COUNT() FROM stats WHERE operation = 'view' GROUP BY item_id

This gives me all the items and a count of their views. I can then change 'view' to 'purchase' or 'download' for the other variables. However this means three separate calls to the database.

Is it possible to get all three in one go?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about mysql-query