0

I have a database of products with prices. What I'd like to be able to do is figure out 5 different price ranges such that each range, when ordered by price, will have approximately the same number of rows in it, i.e., if the database has 25 products in it, I'd like to be able to to find out the MAX price of the 5 lowest priced products, the max price of the second group of 5 lowest priced products, etc.

Something along the lines of:

SELECT MAX(price) FROM products GROUP BY count(5)

I realize that using count(5) in the GROUP BY won't work, I'm just curious if something like this is even possible?

  • Define "first". First when ordered by what? – ypercubeᵀᴹ Apr 3 '14 at 22:00
  • Sorry, when ordered by price. Basically I'm adding a "Shop by price" feature to a website with 5 defined ranges (ie. $50 - $100) but I want to be able to define those ranges such that all 5 ranges will have approximately the same number of products in each range. – nathangiesbrecht Apr 3 '14 at 22:04
  • And ties, what should happen on ties? What if 2 or more products have the same price? – ypercubeᵀᴹ Apr 3 '14 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.