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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:11:51+00:00 2026-05-31T11:11:51+00:00

Consider a student table with 104 rows in it. I need to create groups

  • 0

Consider a student table with 104 rows in it. I need to create groups with a minimum of 10 students in each groups. In the case with 104 students, I would end up having 10 groups of 10 students and 1 group of 4 students if I iterate on each students and create the grouping. There’s a rule that a group with remaining students cannot have less than 5 students in it (in this case the last group consist of 4 student). Two possible approach I’m trying to do:

  1. Roll up the last group that has less than 5 students and assign each of them to any groups, or
  2. Spread the last group evenly to any groups.

How do I achieve any of these? Many thanks.

Eric

  • 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-31T11:11:53+00:00Added an answer on May 31, 2026 at 11:11 am

    You can use ntile.

    Distributes the rows in an ordered partition into a specified number
    of groups. The groups are numbered, starting at one. For each row,
    NTILE returns the number of the group to which the row belongs.

    Some sample code:

    declare @NumberOfStudents int
    declare @StudentsPerGroup int
    
    set @StudentsPerGroup = 10
    set @NumberOfStudents = 104
    
    select StudentID,
           ntile(@NumberOfStudents / @StudentsPerGroup) over(order by StudentID) as GroupID
    from Students
    

    Try it out on SE-Data.

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

Sidebar

Related Questions

Consider the need to develop a lightweight desktop DB application on the Microsoft platforms.
Consider the Oracle emp table. I'd like to get the employees with the top
Consider an indexed MySQL table with 7 columns, being constantly queried and written to.
Consider the following example where Student inherits from Person : function Person(name) { this.name
consider three entities as student, course, subject Below are the associations - student has_many
Let's say I have a table that represents a super class, students . And
Consider you have 2 classes: Student and Course and a Course can be added
Please consider the following code: class Student { } enum StudentType { } static
I need some opinions on what would be a good approch for using XML
Consider, please this setup for a database backed application. ( in my case DB

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.