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 6726355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:55:04+00:00 2026-05-26T09:55:04+00:00

I have a database in SQLITE (lets call it params) that stores a list

  • 0

I have a database in SQLITE (lets call it params) that stores a list of parameter changes and the times that they changed. ie:

key    paramid    time    val
---    -------    ----    ---
1      7          1.2     0
2      3          2.5     23
3      3          5.6     54
4      3          7.1     76
5      7          8.4     1
6      3          9.2     33
7      9          9.7     22
8      3          10.3    21

I would like to use a query to generate a table that includes every time one parameter changed along with the value of the other parameter when the first parameter changed and the time of the change. ie:

param3Val    latestParam7Val    time
---------    ---------------    ----
23           0                  2.5
54           0                  5.6
76           0                  7.1
33           1                  9.2
21           1                  10.3

Any ideas for doing this efficiently in SQL?

Thanks!

  • 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-05-26T09:55:05+00:00Added an answer on May 26, 2026 at 9:55 am

    You could use:

    SELECT p1.val
         , (SELECT p2.val
              FROM params p2
             WHERE p2.paramid = 7
               AND p2.time < p1.time
             ORDER BY p2.time DESC
             LIMIT 1
           ) latestParam7Val
         , p1.time
      FROM params p1
    

    Alternative with joins:

    SELECT p1.val
         , p2.val
         , p1.time
      FROM params p1
      LEFT JOIN params p2 ON p2.paramid = 7 AND p2.time < p1.time
      LEFT JOIN params p3 ON p3.paramid = 7 AND p3.time < p1.time
                                            AND p3.time > p2.time
     WHERE p3.time IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an SQLite database that stores several hundred or thousand strings, I keep
I have a SQLite database that contains a huge set of log messages. I
I have a database file that is generated on a PC using Sqlite. This
I have a remote database (at the moment sqlite, but eventually mysql) that I
I have an app that uses an SQLite database. With the advent of iCloud
I have an sqlite database full of huge number of URLs and it's taking
I have an sqlite database, and I would like to keep it read-only without
I have an SQLite database, eventually will be a MySQL database and I'm using
I have an SQLite database. I created the tables and filled them with a
I am using the SQLite database and have the following persistent class (simplified): public

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.