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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:59:51+00:00 2026-05-16T20:59:51+00:00

I have a student marks table with schema as given below: Student ——– SNO

  • 0

I have a student marks table with schema as given below:

Student
--------
SNO
Marks

I want to produce a result something as this:

MarksRange   Count
----------   ------
0             10
10             2
20             43
:              :
100            2

The above results shows that there are:

  • 10 students who got a score zero,
  • 2 students how got a score between 1 to 10,
  • 43 from 11-20
  • and so on.

Could anyone please let me know how to write a query which produces this result?

  • 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-16T20:59:51+00:00Added an answer on May 16, 2026 at 8:59 pm

    try this:

    DECLARE @Student table (SNO int,Marks int)
    
    INSERT INTO @Student VALUES (1, 0)
    INSERT INTO @Student VALUES (1, 3)
    INSERT INTO @Student VALUES (1, 45)
    INSERT INTO @Student VALUES (1, 95)
    INSERT INTO @Student VALUES (1, 85)
    INSERT INTO @Student VALUES (1, 97)
    INSERT INTO @Student VALUES (1, 92)
    
    DECLARE @StartNumber int
           ,@EndNumber   int
    SELECT @StartNumber=0
          ,@EndNumber=100
    
    ;WITH AllNumbers AS
    (
        SELECT @StartNumber AS Number
        UNION ALL
        SELECT Number+10
            FROM AllNumbers
            WHERE Number<@EndNumber
    )
    SELECT
        n.number AS MarksRange,COUNT(s.SNO) AS CountOf
        FROM AllNumbers               n
            LEFT OUTER JOIN @Student  s ON s.Marks=n.Number OR (s.Marks>n.Number-10 AND s.Marks<=n.Number)
        GROUP BY n.number
    

    OUTPUT:

    MarksRange  CountOf
    ----------- -----------
    0           1
    10          1
    20          0
    30          0
    40          0
    50          1
    60          0
    70          0
    80          0
    90          1
    100         3
    

    if you are not on SQL Server 2005+ you need to replace the CTE with a Numbers table. and use a query like:

    SELECT
        n.number,COUNT(s.SNO),0 AS CountOf
        FROM Numbers                  n
            LEFT OUTER JOIN @Student  s ON s.Marks=n.Number OR (s.Marks>n.Number-10 AND s.Marks<=n.Number)
        WHERE n.Number>=@StartNumber AND n.Number<=@EndNumber AND CONVERT(decimal(3,1),n.Number/10)=n.Number/10.0
        GROUP BY n.number
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code struct Student { char name[48]; float grade; int marks[10,5]; char
I have a mysql table used to score marks of an individual student: studentID
i have a table named students which have student details id,mark,name i want to
In SQL server 2008, I have below table Score. I want to show Score1
Say I have a list of student names and their marks. I want to
I have following two tables (student and marks): In student table I have information
I have this table in sql server 2005: id student active 1 Bob 1
I have varchar type column in my sql table(SQL 2008) for storing student marks.
I have student.xml file and am parsing this file using SAX Parser and now
I have a Student and a Teacher model in my app. I want a

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.