The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Calculating quantiles in SQL figaro UNIX for Dummies Questions & Answers 3 11-20-2007 05:55 PM
Calculating the average kekanap Shell Programming and Scripting 2 01-26-2007 09:36 AM
compare files and calculating tonet Shell Programming and Scripting 6 01-26-2007 06:13 AM
calculating size of int apoorvasharma80 High Level Programming 10 11-01-2006 06:44 PM
Calculating the day of the week ligs UNIX for Dummies Questions & Answers 4 10-27-2001 10:28 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 12-06-2007
figaro figaro is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 268
Calculating changes in non-contiguous data

I want to calculate day-to-day changes in a data set. In an ideal situation the following would suffice:
Date x
2007-01-01 5
2007-01-02 8
2007-01-03 4
2007-01-04 3
2007-01-05 10
2007-01-06 10
2007-01-07 2
2007-01-08 10
2007-01-09 1
2007-01-10 8

SELECT D1.date, (D1.x-D2.x)/D2.x AS change
FROM data AS D1 INNER JOIN data AS D2 ON D1.date=D2.date+1;

This will not work however for non-contiguous dates. In other words , what would be the suggested SQL query for a data set as follows ?

2007-01-01 5
2007-01-02 8
2007-01-03 4
2007-01-04 3
2007-01-05 10
2007-01-08 10
2007-01-09 2
2007-01-10 10
2007-01-11 1
2007-01-12 8

where day 6 and 7 constitute a weekend for which no samples are present. My initial thought would be to have a temporary table with the following structure : id - date - x
where id is a contiguous autonumber and the resulting query would be:

SELECT TD1.date, (TD1.x-TD2.x)/TD2.x AS change
FROM tempdata AS TD1 INNER JOIN tempdata AS TD2 ON TD1.id=TD2.id+1;

But the question is, how should this table be constructed, particularly because not all databases support autonumbers? Any other approaches which are perhaps more straightforward?
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:11 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0