473,659 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculating moving difference

Can some one please help me on this? I got 2 records by individual
with some fileds, one associates with the min date and the other one
assocaites with max date. So lay out looks as follows:

Key_ID | Dates_Min_Max Avg_Weight
1234 1/2/2004 12
1234 1/2/2006 24

I need to get the difference change between the weights for individual
ids that is group by Key_ID and find the percent change. Some thing
like this: (MAx_Row - Previos Row)/Previous Row * 100.

How to do this? How do I get the previos row between 2 records if I
order by the date? Any suggestions? Thanks

Jun 18 '06 #1
1 1736
Sumon wrote:
I need to get the difference change between the weights for individual
ids that is group by Key_ID and find the percent change. Some thing
like this: (MAx_Row - Previos Row)/Previous Row * 100.


Whenever you compare values on two rows, you usually have to do a JOIN
to get them both on the same row of the result set, so you can compare
the values.

SELECT ((t2.avg_weight - t1.avg_weight) / t1.avg_weight) * 100
AS pct_difference
FROM tablename AS t1 JOIN tablename AS t2
ON t1.key_id = t2.key_id AND t1.dates_min_ma x < t2.dates_min_ma x;

Regards,
Bill K.
Jun 19 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4467
by: Hans Gruber | last post by:
Hi all, I have been struggling with a problem all day, I have been unable to come up with a working solution. I want to write a function which takes 2 unix timestamps and calculates the difference. I want it to return the difference in years, months, days, hours, minutes and seconds (a complete summary). Keeping into account of course that these are 2 real dates, I dont want it to work with 30.475 as an average number of days in a...
6
9468
by: Stephen Miller | last post by:
Firstly, sorry for the long post, but I've included a fair bit of sample data. Im doing a comparision of 10yr Bond prices and CPI adjustments, with an 18 week moving average of the CPI. I'm using a nested sub-query to calculate the moving average, but I'm having difficulty selecting exactly 18 data points (ie When I include the 'HAVING COUNT(C1.Closes) = 18' line, I get no results). Can anyone help?
10
6631
by: riki | last post by:
hello, i need to calculate num of days between 2 dates... i get separate parts of dates from html form, then i need to "make" begining and ending date and calculate difference between them... something like this, in sybase: DAYS(YMD(?YEAR?,?MONTH?,?DAY?), YMD(?YEAR1?,?MONTH1?,?DAY1?)) thnx
2
13600
by: Wayne Aprato | last post by:
I've read most, if not all, of the posts on moving average and still can't find a simple solution to my problem (if a simple solution exists!) I have a table with 2 fields: Hours and Injuries. I have a query based on this table which shows these 2 fields and calculates a third field: Frequency Rate, based on a formula which uses the Hours and Injuries fields. Is there a simple way of A: using yet another calculated field in the query...
1
4301
by: Tony Williams | last post by:
I have a table with two fields, txtvalue (a number field) and txtmonth ( a date/time field). I want to create a report that shows the difference in value between the value in txtvalue in one value of txtmonth and the value of txtvalue in another value of txtmonth and the percentage increase . For example if I have the value 1000 in 30/03/03 and the value 1100 in 30/03/04 How do I calculate the difference as 100 and the increase as 10%. I...
3
12931
by: Ron Vecchi | last post by:
I need to calculate the age of a person based on a DateTime BirthDate I was thinking TimeSpan ts = DateTime.Now - BirthDate; //I can get the days but not years. // I could check each year from their year of birth, count the days in the year and compare with the days returned from timespan
3
1744
by: laurentc | last post by:
Dear all, I have a simple table, with only the following fields: - Key - MyDate - Price I would like to biuld a Query which uses these fields and which make some
5
3483
by: Julius | last post by:
Hej dudes, I need to calc the difference between two timestamps / dates ... For example what i need to calculate: Date 1: 2007.11.06 - 20:13:04 Date 2: 2007.11.07 - 21:13:04 Difference: 1 day, 1hour
15
2436
by: mcjason | last post by:
I saw something interesting about a grid pair puzzle problem that it looks like a machine when you find each that work out the way it does and say with all the others that work out the way they do together overlapping common pieces but say connected each working out as connected, but together as connected it's connected with the others connected. a whole machine where connected together is a condition of the machine together as...
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.