in reply to Re: find difference in dates/items in same column
in thread find difference in dates/items in same column
This does work like you say by creating the T and T1 alias/copy tables then you line up the sequence numbers (rank1 and rank2) and process the columns of interest.SELECT a.brand, a.date AS newdate, b.date AS olddate, DATEDIFF(a.date,b.date) AS diff FROM( SELECT brand, date, ( SELECT count(*) FROM test WHERE brand=T.brand AND date<T.date )+1 AS rank1 FROM test AS T ) AS a INNER JOIN ( SELECT brand, date, ( SELECT count(*) FROM test WHERE brand=T1.brand AND date<T1.date ) AS rank2 FROM test2 AS T1 ) AS b ON (a.rank1=b.rank2) AND (a.brand = b.brand) ORDER BY a.brand, a.date DESC ;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: find difference in dates/items in same column
by dragonchild (Archbishop) on Nov 14, 2008 at 20:14 UTC | |
by zerocred (Beadle) on Nov 15, 2008 at 07:12 UTC | |
by dragonchild (Archbishop) on Nov 15, 2008 at 17:18 UTC | |
by zerocred (Beadle) on Nov 15, 2008 at 22:32 UTC | |
by ccn (Vicar) on Nov 15, 2008 at 07:46 UTC | |
by zerocred (Beadle) on Nov 15, 2008 at 22:04 UTC |