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

  • Home
  • SEARCH
  • 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 3493304
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:51:58+00:00 2026-05-18T11:51:58+00:00

i have table which include my product table’s logs like that: process_time product_id product_type_id

  • 0

i have table which include my product table’s logs like that:

process_time             product_id  product_type_id
04.07.2009 14:08:43      5           4
05.07.2009 15:08:43      5           4
06.07.2009 16:08:43      5           6
07.07.2009 16:08:43      5           6
08.07.2009 17:08:43      5           4
08.07.2009 18:08:43      5           4

I want to write a query which shows the changes of product_type_id. For the example above, the result of my query should be like that:

process_time             product_id  product_type_id
04.07.2009 14:08:43      5           4
06.07.2009 16:08:43      5           6
08.07.2009 17:08:43      5           4

How can I write this query?

  • 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-18T11:51:59+00:00Added an answer on May 18, 2026 at 11:51 am

    Like this:

    select * from
    (select process_time, product_id, product_type_id
    ,lag(product_type_id) over (partition by product_id order by process_time) as prevrow
    ,lead(product_type_id) over (partition by product_id order by process_time) as nextrow
    from products )
    where nextrow <> product_type_id or nextrow is null;
    

    For all who like to see how this works:

    create table products (process_time  timestamp, product_id number, product_type_id number);
    
    insert into products values (to_date('2009-07-04 14:08:43','YYYY-MM-DD hh24:mi:ss'),5,4);
    insert into products values (to_date('2009-07-05 15:08:43','YYYY-MM-DD hh24:mi:ss'),5,4);
    insert into products values (to_date('2009-07-06 16:08:43','YYYY-MM-DD hh24:mi:ss'),5,6);
    insert into products values (to_date('2009-07-07 16:08:43','YYYY-MM-DD hh24:mi:ss'),5,6);
    insert into products values (to_date('2009-07-08 17:08:43','YYYY-MM-DD hh24:mi:ss'),5,4);
    insert into products values (to_date('2009-07-08 18:08:43','YYYY-MM-DD hh24:mi:ss'),5,4);
    
    commit;
    
    select process_time, product_id, product_type_id
    ,lag(product_type_id) over (partition by product_id order by process_time) as prevrow
    ,lead(product_type_id) over (partition by product_id order by process_time) as nextrow
    from products 
    order by process_time;
    
    select * from
    (select process_time, product_id, product_type_id
    ,lag(product_type_id) over (partition by product_id order by process_time) as prevrow
    ,lead(product_type_id) over (partition by product_id order by process_time) as nextrow
    from products )
    where nextrow <> product_type_id or nextrow is null;
    
    commit;
    
    drop table products;
    

    Executed we get:

    Table created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    Commit complete.
    
    PROCESS_TIME                    PRODUCT_ID PRODUCT_TYPE_ID    PREVROW    NEXTROW
    ------------------------------- ---------- --------------- ---------- ----------
    04-JUL-09 02.08.43.000000 PM             5               4                     4
    05-JUL-09 03.08.43.000000 PM             5               4          4          6
    06-JUL-09 04.08.43.000000 PM             5               6          4          6
    07-JUL-09 04.08.43.000000 PM             5               6          6          4
    08-JUL-09 05.08.43.000000 PM             5               4          6          4
    08-JUL-09 06.08.43.000000 PM             5               4          4           
    
    
    6 rows selected.
    
    PROCESS_TIME                    PRODUCT_ID PRODUCT_TYPE_ID    PREVROW    NEXTROW
    ------------------------------- ---------- --------------- ---------- ----------
    05-JUL-09 03.08.43.000000 PM             5               4          4          6
    07-JUL-09 04.08.43.000000 PM             5               6          6          4
    08-JUL-09 06.08.43.000000 PM             5               4          4           
    
    
    3 rows selected.
    Commit complete.
    Table dropped.
    
    • 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 is full of arbitrarily formatted phone numbers, like this
In MySQL table, I have a field called Tag, which may include multiple comma-delimited
I have a database table (named Topics) which includes these fields : topicId name
I have a table which is referenced by foreign keys on many other tables.
I have a table which contains my server status create table ServerStatus ( ServerId
I have a table which defines a child-parent relationship between nodes: CREATE TABLE node
I have a table which holds flight schedule data. Every schedule have an effective_from
If you have a table which holds history (updates, deletes) from another table, how
In a SQL server database, I have a table which contains a TEXT field
I have a table y Which has two columns a and b Entries are:

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.