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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:50:08+00:00 2026-05-16T15:50:08+00:00

I have an int field in my table scores . It can be a

  • 0

I have an int field in my table scores. It can be a number between 0 and 100. There are over a 1000 rows in that table. I want to select the number of rows that fall between ranges 0-25, 26-50, 51-75 and 76-100.

So basically, if this is my scores table

score (int)
------------
 10
 20
 12
 56
 43
 90
 87

The output of the query should look like this ( let’s call the ranges R1, R2, R3, R4 )

R1   R2   R3   R4
------------------
3    1    1    2

Let me know if something’s not clear.

EDIT I got this far

SELECT CASE score
WHEN score BETWEEN 0 AND 25 THEN 'R1'
WHEN score BETWEEN 26 AND 50 THEN 'R2' 
WHEN score BETWEEN 51 AND 75 THEN 'R3' 
ELSE 'R4'
END, COUNT(*)
FROM scores

But when I put a AS range after END, I get an error. (UPDATE: nvm this, it supposed to be AS ‘range’, with quotes)

Also, if score is 0, it shows up under R2 and not R1. Why is that?

  • 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-16T15:50:09+00:00Added an answer on May 16, 2026 at 3:50 pm
        create table scores (score int)
    
        insert into scores values(5);
        insert into scores values(15);
        insert into scores values(25);
        insert into scores values(30);
        insert into scores values(35);
        insert into scores values(40);
        insert into scores values(45);
        insert into scores values(55);
        insert into scores values(65);
        insert into scores values(80);
        insert into scores values(90);
        insert into scores values(95);
        insert into scores values(75);
        insert into scores values(50);
    
    
         select SUM(case t.rank when 1 then c else 0 end) as R1,
                 SUM(case t.rank when 2 then c else 0 end) as R2,
                 SUM(case t.rank when 3 then c else 0 end) as R3,
                 SUM(case t.rank when 4 then c else 0 end) as R4
          from
          (         
            select TRUNCATE(score / 26,  0) + 1 rank, count(*) c
             from scores
            group by truncate(score / 26, 0) + 1
          ) t
    

    result:

    R1   R2  R3 R4
    --------------
    3    5    3  3  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a table with an int field - field_1. I want to insert
I have a table in which there is an int field . This field
I have a table in Sql Server that contain an int field price that
I have this Points table: =========================================== FIELD : TYPE =========================================== id int(11) user_id int(11)
In my class, I have field int count . I want to create a
I'm newb with generics/iterators/enumerators etc. I have code, it keeps field number (int) and
Suppose I have the following table: Table: Score field: ID: uniqueidentifier field: Departmentid: int
I have a table called posts having an INT field posted and a table
I have an int field in my product table called product_stat which is incremented
I have a table mytable where is the 2 unique int field # SQLAlchemy

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.