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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:49:10+00:00 2026-06-18T00:49:10+00:00

I am having issues writing a query and was hoping someone might be able

  • 0

I am having issues writing a query and was hoping someone might be able to offer some advice. The data is related to the geology of bore holes. The From and To fields are the depth down the bore hole.

table1:

holeID --- | --- From ---|---To---|---FMN---|---Rocktype ---|
MW1------|-------0-------|---10---|-----X-----|--------13-------|
MW1------|-------10-----|---20---|-----X-----|--------122------|
MW1------|-------20-----|---30---|-----Y-----|--------177------|
MW1------|-------30-----|---40---|-----Y-----|--------146------|
MW1------|-------40-----|---50---|-----Z-----|--------145-------|
MW1------|-------50-----|---60---|-----X-----|--------1----------|
MW1------|-------60-----|---70---|-----X-----|--------123-------|
MW1------|-------70-----|---80---|-----X-----|--------121-------|
MW1------|-------80-----|---90---|-----Z-----|--------120-------|

Which I would like to condense to:

holeID --- | --- From ---|---To---|---FMN---|
MW1------|-------0-------|---20---|-----X-----|
MW1------|-------20-----|---40---|-----Y-----|
MW1------|-------40-----|---50---|-----Z-----|
MW1------|-------50-----|---80---|-----X-----|
MW1------|-------80-----|---90---|-----Z-----| 
  • 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-18T00:49:11+00:00Added an answer on June 18, 2026 at 12:49 am

    SQL Fiddle

    select holeid, "from", "to", fmn
    from (
        select
            holeid,
            first_value("from") over(partition by p order by "from") as "from",
            first_value("to") over(partition by p order by "to" desc) as "to",
            fmn
        from (
            select
                holeid, "from", "to", fmn,
                count(p or null) over(partition by holeid order by "from") p
            from (
                select
                    holeid, "from", "to", fmn,
                    lag(fmn, 1, '') over(partition by holeid order by "from") != fmn p
                from table1
            ) s
        ) s
    ) s
    group by 1, 2, 3, 4
    order by 1, 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be a simple answer, but I am having some issues writing this
I am writing a function to update my XML and am having some issues.
I am having some performance issues with a query I am running in SQL
I am having some issues with writing and reading with android. here is my
I'm having issues with a bit of code that I am writing in C#.
I am having issues with FileStreams. I'm in the process of writing a C#
I'm writing a plug-in for another program in C#.NET, and am having performance issues
Hi I'm having some problem with a PHP page: I'm writing a little CMS
I'm having issues writing a C function that reads a string from STDIN, and
I'm having an issue writing a tough query. I have the following table (as

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.