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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:17:20+00:00 2026-05-31T01:17:20+00:00

I have table id year month day 1 2012 1 1 2 2012 1

  • 0

I have table

        id  year  month  day  
         1  2012    1     1
         2  2012    1     2
         3  2012    1     3
         4  2012    1     4
         5  2012    1     5
         6  2012    1     7
         7  2012    1     8
         8  2012    1     9
         9  2012    1     10
         10 2012    1     11

from the above table i want to generate the following output when count of id reaches the
multiple of 5

          day_start day_end
             1         5   
             5         11 
  • 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-31T01:17:21+00:00Added an answer on May 31, 2026 at 1:17 am

    This will work in SQL Server. Using the row_number rather than the id field value will prevent errors if you delete rows and the sequence of ids is no longer complete.

    Note: I’m basing this answer on the fact that you said the “count of id” reaches 5, and not “the value of id”. Which to me means “every 5 records, regardless of the id value”. If that’s not the case, then leave a comment and I’ll remove this answer, since Mark’s will work fine.

    select case when rownumber = 5 then 1 else rownumber - 5 end as day_start, day_end
    from
    (
        select row_number() over (order by id) as RowNumber, [day] as day_end
        from table1
    ) t
    where rownumber % 5 = 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have day, month, year, value columns in one table, here i need to
I have table as P_Id | userid | year | month | day -----+--------+------+-------+------
I have the following two tables: ITEM AREA YEAR MONTH DAY QTY OL EXQTY
If I select from a table group by the month, day, year, it only
I have table like this create table tbl_1( year int, month int, day int
I have 2 tables as follow : table1 has these fields: year,day,month,name table2 has
I have a table like: id number year I want to find holes, or
I have a birthdate, year, month, day columns where columns year,month,day are foreign key
Below I have table - Company id name value year 1 IBM 10 2011
I have a table with the following columns: ref_year, ref_no, inv_id, start_date, end_date The

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.