2018-07-07 14:57 GMT+02:00 Simon Slavin <slav...@bigfraud.org>:

> On 7 Jul 2018, at 12:04pm, Cecil Westerhof <cldwester...@gmail.com> wrote:
>
> > ​I went for the following solution:
> >    UPDATE
> ​​
> ​​
> selectRandom
> >    SET    lastUsed    = DATE('now', 'localtime')
> >    ,      lastUsedIdx = (
> >        SELECT IFNULL(MAX(lastUsedIdx), 0)
> >        FROM   selectRandom
> >        WHERE  lastUsed = DATE('now', 'localtime')
> >    ) + 1
> >    WHERE  description = :teaToBrew
> >
> > I would think that is not to convoluted.
>
> Elegant.  I understood it.  Though I was primed with what you're trying to
> do.
>

​I drink a lot of different sorts of tea. Often I have between 20 and 30
different types. To make the choice easier I wrote a little ​
​application​

​that only shows a few to select from. The longer ago that I drank a tea,
the greater the change it is shown in the list.​ I also display the latest
tea I drank. (I have several chai teas, but you should not drink it more as
once in three days.) To show them in the correct order (not important, but
nice to have) I wanted this index. For that I use:
    SELECT   *
    FROM     teaInAndOutStock
    ORDER BY LastUsed    DESC
    ,        lastUsedIdx DESC
    LIMIT    :limitNr

teaInAndOutStock is a view on selectRandom.
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to