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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.