nickspick Posted September 22, 2006 Share Posted September 22, 2006 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 numRowsFROM 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 More sharing options...
jvrothjr Posted September 22, 2006 Share Posted September 22, 2006 You would want to use the option [between] on your select query statement[code=php:0]$query = "select * from pricing where (Mcov between $Minprice and $Maxprice)";[/code] Link to comment https://forums.phpfreaks.com/topic/21691-grouping-by-numbers/#findComment-96853 Share on other sites More sharing options...
fenway Posted September 25, 2006 Share Posted September 25, 2006 And if you use that with a proper min/max/ceil/floor function, you can get MySQL to dump out the range as well. Link to comment https://forums.phpfreaks.com/topic/21691-grouping-by-numbers/#findComment-97911 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.