For example I have a table MyTable like this:
Id Value Rate
1 10
2 30
3 40
4 60
5 100
Rate is defined as: Rate = [ Value(id) – Value(5) ] / [ 5 – id ] , for id from 1 to 4.
I’m thinking of doing this:
INSERT INTO MyTable (Id, Rate)
SELECT Id,
??? real work goes hereFROM MyTable
LIMIT 4
ON DUPLICATE KEY UPDATE Rate=VALUES(Rate);
But can someone help me how to do the “rate” part? Thanks!
Another thing, if I define Id like this:
Id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY
Is it possible the program could assign the value of Id not continuous, for example, the values of Id like this: 1, 2, 4, 5, 6? I’m asking because if this is possible, my program would fail because I assume the Id values are continuous.
In addition, is it possible the value of Id not starting from 1? For example, the values of Id like this: 2, 3, 4, 5, 6? I’m asking because if this is possible, my program would fail because I assume the Id value always starts from 1 and if there are five rows the last one would be 5.
Thanks for helping!
You can write: