Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7852097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:20:23+00:00 2026-06-02T19:20:23+00:00

I got table T1 where I update some counters values id, unix_time_stamp, counter1, counter10

  • 0

I got table T1 where I update some counters values

id, unix_time_stamp, counter1, counter10
1 , 1333435800     , 55      , 80

then i got table T2 where i copy those values

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

this is done with some trigger function

INSERT INTO T2 (unix_time_stamp, counter1, counter10) SELECT unix_time_stamp, counter1, counter10 FROM T1 WHERE id=1

What i want is to calculate value1, value10 as a

(current_counter1 - last_counter1)/(current_time - last_time)

and put them in this insert.

for example value 1 with timestamp 1333435804 will be

value1=(80-70)/(1333435804-1333435802) = 5

other words

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

but i want this in a little shorter version because i got 10 counters 🙂

Whole situation is little bit complicated, and i got some reason to not do this outside SQL

I am using sqlite

This is just to complicated to me 🙂
Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:20:24+00:00Added an answer on June 2, 2026 at 7:20 pm

    I guess the following query calculates all data you need for your insert clause:

    SELECT 1e0 * (cur.counter1 - prv.counter1)/(cur.unix_time_stamp - prv.unix_time_stamp)   AS [value1]
    , 1e0 * (cur.counter10 - prv.counter10)/(cur.unix_time_stamp - prv.unix_time_stamp)      AS [value10]
    , cur.counter1 AS [cur_counter1], cur.counter10 AS [cur_counter10], cur.unix_time_stamp AS [cur_time]
    , prv.counter1 AS [prv_counter1], prv.counter10 AS [prv_counter10], prv.unix_time_stamp AS [prv_time]
    FROM T1 cur, T1 prv
    WHERE cur.counter1 = (SELECT MAX(aux_0.counter1) FROM T1 aux_0)
    AND prv.counter1 = (SELECT MAX(aux_1.counter1) FROM T1 aux_1 WHERE aux_1.counter1 < cur.counter1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some trouble when trying to update a table by looping cursor which
I have a table where I wish to update some of the rows. All
I've got a data issue with some values stored in an XML column in
I have to update value based on values from another table: update OracleOb..NS.myTable set
I've got a query like this: update table set status = 1 where status
The table I got a table that contains price for some 1 000 000
I'm trying to update a table in Oracle and I'm running into some difficulty.
I've got a situation where I updated one table with some 3rd party utility,
I've got about 25 tables that I'd like to update with random data that's
Got this: Table a ID RelatedBs 1 NULL 2 NULL Table b AID ID

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.