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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:59:14+00:00 2026-05-22T12:59:14+00:00

Googling it a bit I found this to be an interesting question. Would like

  • 0

Googling it a bit I found this to be an interesting question. Would like you guys shots.

Having my table

USER    |   MAP |   STARTDAY    |   ENDDAY
1       |   A   |   20110101    |   20110105
1       |   B   |   20110106    |   20110110
2       |   A   |   20110101    |   20110107
2       |   B   |   20110105    |   20110110

Whant I want is to fix user’s 2 case, where maps A and B overlaps by a couple days (from 20110105 until 20110107).
I wish I was able to query that table in a way that it never return overlapping ranges. My input data is falky already, so I don’t have to worry with the conflict treatment, I just want to be able to get a single value for any given BETWEEN these dates.

Possible outputs for the query I’m trying to build would be like

USER    |   MAP |   STARTDAY    |   ENDDAY
2       |   B   |   20110108    |   20110110 -- pushed overlapping days ahead..
2       |   A   |   20110101    |   20110104 -- shrunk overlapping range

It doesn’t even matter if the algorithm causes “invalid ranges”, e.g. Start = 20110105, End = 20110103, I’ll just put null when I get to these cases.

What would you guys say? Any straight forward way to get this done?

Thanks!

f.

  • 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-22T12:59:15+00:00Added an answer on May 22, 2026 at 12:59 pm

    Analytic functions could help:

    select userid, map
    , case when prevend >= startday then prevend+1 else startday end newstart
    , endday
    from
    ( select userid, map, startday, endday
      , lag(endday) over (partition by userid order by startday) prevend
      from mytable
    )
    order by userid, startday
    

    Gives:

    USERID  MAP     NEWSTART        ENDDAY
    1       A       01/01/2011      01/05/2011
    1       B       01/06/2011      01/10/2011
    2       A       01/01/2011      01/07/2011
    2       B       01/08/2011      01/10/2011
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been googling and querying stackoverflow quite a bit but I haven't found this
After googling a bit I have found some tips about how to get online
While I'm googling/reading for this answer I thought I would also ask here. I
From googling around it looks like Xcode (3.1 in my case) should be at
While googling, I see that using java.io.File#length() can be slow. FileChannel has a size()
Lot of googling did not help me! Are there any good dictionary web based
I've been googling for a while now, and can't figure out how to create
I know Googling I can find an appropriate answer, but I prefer listening to
The story: I been googling for some way of displaying computer graphics over the
I've done some Googling, and can't find anything, though maybe I'm just looking in

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.