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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:34:31+00:00 2026-05-29T10:34:31+00:00

The below sample data has a cumulative size for each entry. I am trying

  • 0

The below sample data has a cumulative size for each entry. I am trying to write a query to update the size, with the difference in size with the previous timestamp(For example – row 2 should be updated with (4478.74 – 4476) = 2.74) for the same item name. Please help me on this one.

Row Item     Size       Time
-----------------------------------------------
1   ItemA    4476       7/01/2012 11:15
2   ItemA    4478.74    7/01/2012 11:20
3   ItemA    4478.82    7/01/2012 11:21
4   ItemA    4487.51    7/01/2012 11:29
5   ItemB    1.53       7/01/2012 11:29
6   ItemB    1.67       7/01/2012 11:20
7   ItemB    1.84       7/01/2012 11:21
8   ItemB    2.18       7/01/2012 11:15
  • 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-29T10:34:32+00:00Added an answer on May 29, 2026 at 10:34 am

    You can partition the data by Item and then outer join it to itself on the previous row number:

        create table ItemTotal (id uniqueidentifier, item varchar(10), size numeric(10,2), entry datetime)
    
        insert into ItemTotal values(NEWID(), 'ItemA', 4476, '7/01/2012 11:15');
        insert into ItemTotal values(NEWID(), 'ItemA', 4478.74, '7/01/2012 11:20');
        insert into ItemTotal values(NEWID(), 'ItemA', 4478.82, '7/01/2012 11:21');
        insert into ItemTotal values(NEWID(), 'ItemA', 4487.51, '7/01/2012 11:29');
        insert into ItemTotal values(NEWID(), 'ItemB', 1.53, '7/01/2012 11:29');
        insert into ItemTotal values(NEWID(), 'ItemB', 1.67, '7/01/2012 11:20');
        insert into ItemTotal values(NEWID(), 'ItemB', 1.84, '7/01/2012 11:21');
        insert into ItemTotal values(NEWID(), 'ItemB', 2.18, '7/01/2012 11:15');
    
        with items(id, item, size, entry, rn) as (
        select id, item, size, entry, ROW_NUMBER () OVER (Partition By item order by entry) as rn From ItemTotal t)
        select i.item, i.size, i.entry, i.size - coalesce(o.size, 0) as difference
        from items i
        left outer join items o on o.item = i.item and o.rn = i.rn-1
        order by i.item, i.entry desc
    

    Resulting Output:

    item    size    entry   difference
    ItemA   4487.51 2012-07-01 11:29:00.000 8.69
    ItemA   4478.82 2012-07-01 11:21:00.000 0.08
    ItemA   4478.74 2012-07-01 11:20:00.000 2.74
    ItemA   4476.00 2012-07-01 11:15:00.000 4476.00
    ItemB   1.53    2012-07-01 11:29:00.000 -0.31
    ItemB   1.84    2012-07-01 11:21:00.000 0.17
    ItemB   1.67    2012-07-01 11:20:00.000 -0.51
    ItemB   2.18    2012-07-01 11:15:00.000 2.18
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have block of data sample in XML. Each data has a attribute called
I have a python script which outputs lots of data, sample is as below.
I've been learning C#, and I'm trying to understand lambdas. In this sample below,
Below is the sample data format in my CSV file. date,<options> YYYY-MM-DD,<values> Every next
I have CSV file which has timestamp in the first column as shown below
Below, I've attached a sample of my data as well as a sample of
Below is sample code to create a radio button element with Yes/No options in
In the below code sample, what does {0:X2} mean? This is from the reflection
I've put together a small code-sample below (Currently in C# 3.5 but would also
I have a IObservable [named rows in the sample below] from Reactive extensions framework

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.