Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLite: Select all date-value-pairs where the distance between each date and the first date is a multiple of a specific period
    primarykey
    data
    text
    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.
    1. COMy gut tells me this just isn't possible with SQLite SQL. It might be possible using Postgres WITH RECURSIVE, but it would probably have the same complexity as doing it in a stored procedure. Since SQLite data is local, I'd probably just loop over the possible dates and do a separate query for each.
      singulars
    2. COThanks for your response. I try to figure out this problem all day. I was hoping that there is some kind of loop command in SQLite, but as far as I read, there isn't. An alternative I had in mind was pulling all the dates from the database `curs.execute('''SELECT date, value FROM stockPrices WHERE name= ? AND date BETWEEN ? AND ? ORDER BY date ASC;''', (name, start, end))` and then writing a function in Python which selects the specific dates. But I am still hoping for a more elegant way.
      singulars
    3. COYou could pull the minimum date and the maximum date from the table, then in Python, loop over all the "candidate dates" in this range. For each of these, `select * from stockPrices where date between [candidate - period] and [candidate + period] order by abs(julianday(date)-julianday(?)) asc limit 1`. Depending on whether SQLite and the Python drivers allow this, you might also use a subquery and do something like `select ([subquery]) from values ([candidate1]),([candidate2])`, but that's probably a little out of scope for SQLite.
      singulars
 

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