Note that there are some explanatory texts on larger screens.

plurals
  1. POCalculate difference between rows with counter values in SQL
    primarykey
    data
    text
    <p>I got table T1 where I update some counters values</p> <pre><code>id, unix_time_stamp, counter1, counter10 1 , 1333435800 , 55 , 80 </code></pre> <p>then i got table T2 where i copy those values</p> <pre><code>id, unix_time_stamp, counter1, counter10, value1, value10 1 , 1333435800 , 55 , 80 , 0 , 0 2 , 1333435801 , 60 , 87 , 5 , 7 3 , 1333435802 , 70 , 90 , 10 , 3 3 , 1333435804 , 80 , 100 , 5 , 5 </code></pre> <p>this is done with some trigger function</p> <pre><code>INSERT INTO T2 (unix_time_stamp, counter1, counter10) SELECT unix_time_stamp, counter1, counter10 FROM T1 WHERE id=1 </code></pre> <p>What i want is to calculate value1, value10 as a</p> <pre><code>(current_counter1 - last_counter1)/(current_time - last_time) </code></pre> <p>and put them in this insert.</p> <p>for example value 1 with timestamp 1333435804 will be</p> <pre><code>value1=(80-70)/(1333435804-1333435802) = 5 </code></pre> <p>other words</p> <pre><code>insert into t2 (unix_time_stamp, counter1, counter10, value1) SELECT unix_time_stamp, counter1, counter10, (counter1 - (select counter1 from T1 order by unix_time_stamp DESC LIMIT 1)/ (unix_time_stamp - (select unix_time_stamp from T1 order by unix_time_stamp DESC LIMIT 1) FROM T1 WHERE id=1 </code></pre> <p>but i want this in a little shorter version because i got 10 counters :)</p> <p>Whole situation is little bit complicated, and i got some reason to not do this outside SQL</p> <p>I am using sqlite</p> <p>This is just to complicated to me :) Please help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload