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 4003646
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:10:40+00:00 2026-05-20T08:10:40+00:00

Hail, Stack! I need to select the count of values grouped by ranges. To

  • 0

Hail, Stack!

I need to select the count of values grouped by ranges.

To exemplify, suppose that I have the following values in a table columm: 1,2,4,5,6,8,9,11,13,16

Then, I want to retreave the count of them in ranges of 5, like this:

From  0 to  4 there is 3 values (1,2,4)
From  5 to  9 there is 4 values (5,6,8,9)
From 10 to 14 there is 2 values (11,13)
From 15 to 19 there is 1 values (16)

And so on…

How can I make this in a query?

  • 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-05-20T08:10:40+00:00Added an answer on May 20, 2026 at 8:10 am

    Maybe this is what you want:

    SELECT
        5 * (n div 5) as 'from',
        5 * (n div 5) + 4 as 'to',
        COUNT(*)
    FROM yourtable
    GROUP BY n div 5;
    

    For your sample this query gives you

    +------+------+----------+
    | from | to   | count(*) |
    +------+------+----------+
    |    0 |    4 |        3 |
    |    5 |    9 |        4 |
    |   10 |   14 |        2 |
    |   15 |   19 |        1 |
    +------+------+----------+
    4 rows in set (0.00 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hail, i have a problem to serve file with PHP into client. that when
I have a SharePoint list that gets installed by a feature. I need to
I'm working on an application that will have attachments, and I would like to
I have a perl .exe file that I was to run every ten minutes.
Hail! I want to fetch image from NOT PUBLIC Google Site's page. I'm using
I am working on a small perl program that will open a site and
JavaFX is now out, and there are promises that Swing will improve along with
What's a good way to persist state when restarting a crashed process? I have
I'm doing a full rewrite of an old library, and I'm not sure how
Perverse Hangman is a game played much like regular Hangman with one important difference:

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.