0

is it possible to increment last row with a constant value? I would like to receive a response like this:

Date        |  Value 
-------------------
2013-11-01  |  14.32
2013-11-02  |  15.32
2013-11-03  |  16.32
...         |  ...

I've tried it with Variables:.

SET @INCREMENT := '1.00';
SET @VALUE := '14.32';
SELECT `Date`, @VALUE + @INCREMENT
FROM `table` 
WHERE `Date` > '2013-11-01'

but this shows only one constant value in row2.

Peter
  • 1,224
  • 3
  • 16
  • 28

2 Answers2

1

I think you want to reset the value for each row:

SET @INCREMENT := '1.00';
SET @VALUE := '14.32';
SELECT `Date`, (@VALUE := @VALUE + @INCREMENT) as value
FROM `table` 
WHERE `Date` > '2013-11-01';

Normally when you do this, you would have an order by clause to ensure that the rows are returned in the order you want them to be.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • Oh, yes, that's great. Value ist incresing by Increment. I just inserted an @ in line 3: SELECT `Date`, (@VALUE := @VALUE + @INCREMENT) as value – Peter Dec 05 '13 at 20:09
0

Not sure if you mean this, but this seemed to be the most logical.. Assuming you have an existing table with Date and Value

SET @INCREMENT = 1.00;

SELECT
    Date "date"
 , (Value + @INCREMENT) "value"
FROM 
  table 
WHERE
  Date > '2013-11-01'
ORDER BY
  Date ASC

Or even better (because you dont need the "overhead" off an user variable to calculate this on runtime)

SELECT
    Date "date"
 , (Value + 1.00) "value"
FROM 
  table 
WHERE
  Date > '2013-11-01'
ORDER BY
  Date ASC
Raymond Nijland
  • 11,488
  • 2
  • 22
  • 34