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

  • Home
  • SEARCH
  • 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 8700953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:17:13+00:00 2026-06-13T02:17:13+00:00

I’m trying to find a way to group prices in a database table by

  • 0

I’m trying to find a way to group prices in a database table by price “group”.
So my database table looks something like this:

+-------+------------------+
| Field | Type             |
+-------+------------------+
| id    | int(11) unsigned |
| name  | varchar(255)     |
| price | varchar(30)      |
+-------+------------------+

Those are the relevant fields in my database table.
What I’m trying to accomplish is to run a query that will group results by price range, so items that fall between $1 and $10 would go into group #1; $11 to $20 would go into price group #2, etc… so it should look like this:

+-------------+------------+
| price_group | item_count |
+-------------+------------+
| $1-$10      | 10         |
+-------------+------------+
| $11-$20     | 8          |
+-------------+------------+
| $21-$30     | 22         |
+-------------+------------+
| $31-$40     | 58         |
+-------------+------------+
| $41-$40     | 3          |
+-------------+------------+

I don’t have any code that I’ve tried because I’m not really sure where to begin on this. Still searching trying to find a clue.

  • 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-13T02:17:14+00:00Added an answer on June 13, 2026 at 2:17 am

    You can group by the price (offset by 1 because of where you put your group divisions), divided by ten, cast to an integer. Consider the group $21-$30. If you subtract one, that will be $20-$29. Divide by ten (and cast to integer), anything in that group will return $2, giving you a constant for the price group.

    SELECT CAST((price - 1) / 10 AS UNSIGNED) AS price_group, 
        SUM(item_count) as total_item_count
    FROM table_name
    GROUP BY price_group
    

    Also note that I did SUM(item_count) to get the total for that group.

    The price_group returned here will just be the tens digit. For example, for group “$21-$30”, price_group returned will be “2”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to count the length of a string with PHP. The string
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.