|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Is there adjacent row operation?
I Need help. Problem is like this:
BASE TABLE (say the historical price of product X) Year Price ---- ------ 1960 5 1962 7 1967 15 1970 20 1980 30 1986 44 1992 50 2000 60 QUERY RESULT (with filter say Year Between 1967 And 1986) Year1 Year2 Price1 Price2 PriceInc ----- ----- ------ ------- -------- 1967 1970 15 20 5 1970 1980 20 30 10 1980 1986 30 44 14 the last column is a calculated field (Price2-Price1). can this query be produced by SQL statement? |
|
#2
|
|||
|
|||
|
RE: Is there adjacent row operation?
I'm not sure if it will work, but I think it might:
select Year1, Year2, Price1, Price2, (Price2 - Price1) as PriceInc .... Not sure though, never tried it, but it's worth a shot;) |
|
#3
|
|||
|
|||
|
RE: Is there adjacent row operation?
thanks, ShaneO and sager, for your response. i really appreciated your time spent on this.
However i must note that the peculiarity of this problem is the fact that the query result is always consecutive rows. And note that for a given row, the first column value (Year1) is always the same as the second column value (Year2) of the PRECEDING row. This is also true for the Price columns. I really need help on this one. Thanks. lambda |
|
#4
|
|||||
|
|||||
|
RE: Is there adjacent row operation?
Here is a hack:
php Code:
|
|
#5
|
|||
|
|||
|
RE: Is there adjacent row operation?
The 2nd year comparison in $query1 should be <=
|
|
#6
|
|||||
|
|||||
|
RE: Is there adjacent row operation?
hang-on ... wait a minute ... stop.
Sorry 'bout that but the mountain dew is wearing off and its past my bedtime. This is it: php Code:
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Is there adjacent row operation? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|