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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:21:03+00:00 2026-06-18T06:21:03+00:00

Can Analytical function be used to collapse these record’s from this ssid start_time end_time

  • 0

Can Analytical function be used to collapse these record’s
from this

ssid  start_time            end_time                op_code
65F   08/JAN/2013 14:18:33  08/JAN/2013 14:18:34    2
65F   08/JAN/2013 14:18:53  08/JAN/2013 14:18:54    2
65F   08/JAN/2013 14:18:55  08/JAN/2013 14:18:59    3
65F   08/JAN/2013 14:19:33  08/JAN/2013 14:19:34    2
65F   08/JAN/2013 14:19:53  08/JAN/2013 14:19:54    2
65F   08/JAN/2013 14:19:55  08/JAN/2013 14:19:59    3
72F   08/JAN/2013 14:20:55  08/JAN/2013 14:20:56    2
72F   08/JAN/2013 14:19:57  08/JAN/2013 14:19:59    2

to this

ssid  start_time            end_time              c_dt                 op_code
65F   08/JAN/2013 14:18:33  08/JAN/2013 14:18:54  08/JAN/2013 14:18:59   2
65F   08/JAN/2013 14:19:33  08/JAN/2013 14:19:54  08/JAN/2013 14:19:59   2
72F   08/JAN/2013 14:19:57  08/JAN/2013 14:20:56

or i have to processes this in a for loop only .
I am on Oracle 11gR2

If the next op_code is 2
then the end_time becomes the end_time of the next record and we go on replacing the end
time of this record until a same ssid with op_code 3 arrives.
and when the record with the op_code 3 arrives we generate the c_dt which is the end_time of record with same ssid but with op_code 3.
we start this process all over again for the next record

If we do not find a record with op_code 3 for a particular ssid then the c_dt will be null
but the end_time will be the end_time of the next record with same ssid.

Hope i am clear on this tricky logic

  • 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-18T06:21:04+00:00Added an answer on June 18, 2026 at 6:21 am

    I’ll be the first to say that this is NOT pretty, but it should get you going in the right direction.

    First, create a CTE with all your records with a corresponding row number.

    Second, create another CTE which has the next record where op code is not the same.

    Third, create another CTE which has the min row number, max row number, and next row number (potentially null) and use this to get your results.

    It very well could be simplified, but this was my first attempt.

    WITH CTE AS (
      SELECT 
         t.ssid,t.start_time,t.end_time,t.op_code
        ,ROW_NUMBER() OVER (ORDER BY Start_Time) rn
      FROM YourTable t
    ) , 
    CTE2 AS (
      SELECT C.SSID, C.RN, MIN(C2.RN) RN2
      FROM CTE C
        LEFT JOIN CTE C2 ON 
          C.RN < C2.RN AND 
          C.OP_CODE <> C2.OP_CODE AND 
          C.SSID = C2.SSID
      WHERE C.Op_Code = 2
      GROUP BY C.SSID, C.RN
    ) ,
    CTE3 AS (
      SELECT SSID, MIN(RN) MinRN, MAX(RN) MaxRN, RN2 
      FROM CTE2
      GROUP BY SSID, RN2
    ) 
    SELECT c.ssid, 
      c.start_time, 
      c3.end_time, 
      c4.end_time c_dt, 
      c.op_code
    FROM CTE c
       JOIN CTE3 c2 ON c.RN = c2.MinRN
       JOIN CTE c3 ON c2.MaxRN = c3.RN
       LEFT JOIN CTE c4 ON c2.RN2 = c4.RN
    

    And here is the SQL Fiddle.

    Good luck.

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

Sidebar

Related Questions

I need to display some analytics to the user; however, occasionally these analytics can
I'm getting used to Haskell's higher-order functions. Usually I can replace explicit patterns of
Can we use nested analytic function within analytic function? We can use another analytic
So a client asked me to create a Conversion tracking He said this: Can
Someone somewhere has had to solve this problem. I can find many a great
i used a native query to call a function in my postgresql database, code
Based on the privacy requirements from the ios store, can we include analytics like
Can somebody please tell me how I can get google analytics on every page
How can be possible to use Google analytic with blogger dynamic views? I cannot
I can't find any specific documentation about the dispatchPeriod variable in the Google Analytics

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.