tags:

views:

17

answers:

1

I have a MySQL table and I am looking to create a stats page on the data.

Id (integer), Pri (integer), blab1, blab2, blab3, ect...

The "pri" field has a number between 0-1000. I would like to how the rows are spread across the pri in the table. I am looking for a way to group the "pri" by 100s and count the number of rows in each group.

For example:

Range   | Count
-----------------
  0- 99 |  999
100-199 |   50 
200-299 | 3587 

The easier way would be to run 10 separate queries for each range, (WHERE pri >= 400 AND pri < 500) but I was wondering if there was a easier way?

+3  A: 

You can always trunc the pri column to like so:

SELECT 
    truncate(pri/100,0)*100 AS Range_Start,
    count(*)
FROM ...
GROUP BY
    truncate(pri/100,0)*100;
ar
I gt the following error message #1305 - FUNCTION trunc does not exist
Steven smethurst
Sorry, in MySQL you have to use `truncate`, http://dev.mysql.com/doc/refman/5.1/en/mathematical-functions.html#function_truncate
ar