![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
| Display Modes | Rate This Thread |
|
|