Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8504495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:02:53+00:00 2026-06-11T02:02:53+00:00

I have a products table with a column for price and master category. I’d

  • 0

I have a products table with a column for price and master category.

I’d like to query my DB to find the range of prices there are for a given category (or all categories). This range of prices would then be broken into an appropriate number of price-ranges ie £0-£5 £5-£10 etc…

I can’t get my head around how to do this; do I need to do this all with php?

EDIT: having had a wee think about it, to clarify, I would like to end up so that whatever category is being listed, I can show perhaps 4 price ranges with roughly equal numbers of products in each. I can’t get my feeble mind around it 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:02:55+00:00Added an answer on June 11, 2026 at 2:02 am

    For the min and max price per category:

    SELECT category, min(price) as min_price, max(price) as max_price
    from Products
    Group BY category
    

    For ranges directly in a query you could do something like this

    SELECT
        category,
        SUM(CASE WHEN price BETWEEN 0 AND 5 THEN 1 ELSE 0 END) as zero-five,
        SUM(CASE WHEN price BETWEEN 5 AND 10 THEN 1 ELSE 0 END) as five-ten,
        ...
    from Products
    Group BY category
    

    yields

    Category  zero-five  five-ten
    Cat1        2          4
    Cat2        3          6
    

    or

    SELECT category, range, count(*)
    FROM (
        SELECT 
            category,
            CASE WHEN price BETWEEN 0 to 5 THEN '0-5'
                 WHEN price BETWEEN 5 to 10 THEN '5-10'
                 ...
                 ELSE '10+'
            END as range
        FROM products
    )
    group by category, range
    

    yields

    Category  range count
    Cat1       0-5    2      
    Cat1       5-10   4      
    Cat1       10+    0
    Cat2       0-5    3      
    Cat2       5-10   6      
    Cat2       10+    0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now I have 4 tables: table categories: -id -category table products: -id -product -price
I have a table with products that have columns like this: price[decimals 8,5] and
I have a price column in products table. I wonder which MySQL type is
Imagine there is a Price column in Products table, and the price may change.
I am using Mysql database. I have 3 table-: table Column tier_price customer_id,sku(Unique),price,website catalog_product
I have a products table with a column of type SET (called especialidad), with
I have a 4 column table of products in template,each item in table has
I have a table products , and I have columns like product_name , product_id
For an e-shop I have Products table (id, name, price, description) Attributes table (attribute
I have a products table which contains duplicate products by a column id_str and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.