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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:12:45+00:00 2026-06-13T00:12:45+00:00

I have the below table which has 2 columns.I need to write a query

  • 0

I have the below table which has 2 columns.I need to write a query which will return 3 columns,the first 2 column should match the 2 columns present in the table and the 3rd column should group into n splits.
for example in this case I want to split into 4 groups.so 1st 4 rows should return 1 in column 3,2nd 4 rows should return 2, 3rd 4 rows should return 3 and finally last 3 rows(as there are in total 15 rows) should return 4.

DECLARE @NAMES TABLE ( [ID] INT IDENTITY, [NAME] VARCHAR(20) )   
INSERT INTO @NAMES SELECT 'NAME1' 
UNION ALL 
SELECT 'NAME2' 
UNION ALL 
SELECT 'NAME3' 
UNION ALL 
SELECT 'NAME4' 
UNION ALL 
SELECT 'NAME5' 
UNION ALL 
SELECT 'NAME6' 
UNION ALL 
SELECT 'NAME7' 
UNION ALL 
SELECT 'NAME8' 
UNION ALL 
SELECT 'NAME9' 
UNION ALL 
SELECT 'NAME10' 
UNION ALL 
SELECT 'NAME11' 
UNION ALL 
SELECT 'NAME12' 
UNION ALL 
SELECT 'NAME13' 
UNION ALL 
SELECT 'NAME14' 
UNION ALL 
SELECT 'NAME15' 
  • 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-13T00:12:45+00:00Added an answer on June 13, 2026 at 12:12 am

    try NTILE() function in SQL Server

    select ID, Name, ntile(4) over (order by Name) from @Names
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which has the below columns. Ticket_id (Primary key, Int) Attachment1
I have a T-SQL query as below which queries a table holding the search
I have a consumer table which has the columns - Email, AccountState and DateCreated
I have a table which has a header row, but also a header column
I have a table, call it MyTable which has a column, say myvalue. I
I have a Generic List object which hold below table as its own value.
I have two table masterTbl and detailTbl which structure is given below... --PRIMARY TABLE
I have the following listbox below which binds to a database table of image
I have a piece of matlab code below which reads data from a table.
I have the below table. I am trying to get tbody column bgcolors matching

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.