Jump to content

Grouping by numbers


nickspick

Recommended Posts

Hi,

I've got a table with a column that stores prices that vary considerably. These prices will be used to create options for the user to select a price range. Rather than presenting every number I want to group the numbers into ranges and display these along with a count of how many results fall into each range.

I've been able to achieve the same concept with datestamps (See example) but am stumped with what to use for just plain numbers.
[pre]
[color=blue]SELECT
DATE_FORMAT(FROM_UNIXTIME(date), '%Y') as new_date,
COUNT(*) AS numRows
FROM
table
GROUP BY
new_date[/color]
[/pre]
The above example will group all timestamps into years and also count how records are contain within each group. I'd like a similar thing for numbers but grouping them into 1000s or 10000s.

Any ideas?

Many thanks!
Link to comment
https://forums.phpfreaks.com/topic/21691-grouping-by-numbers/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.