Re: Check if there 6 last records of same type without gaps

From: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
To:
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Check if there 6 last records of same type without gaps
Date: 2016-09-06 13:38:24
Message-ID: CAADeyWiPTT1oFv+FxdB+i7R8Vkhc0-HDT_en=vQ8-yXwfE1dow@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Sandor, this has worked, thank you -

On Tue, Sep 6, 2016 at 3:35 PM, Sándor Daku <daku(dot)sandor(at)gmail(dot)com> wrote:

>
> Of course you need the played field you relied on it in the order by
> clause. You can use the result of a select in a from clause of another
> select.
>
> SELECT SUM(skips) from (SELECT CASE WHEN action='skip' THEN 1 ELSE 0 END
> as skips, played
> FROM words_moves
> WHERE gid = 3
> ORDER BY played DESC
> LIMIT 6) as skipscount;
>
>
words=> SELECT SUM(skips) from (SELECT CASE WHEN action='skip' THEN 1 ELSE
0 END as skips, played
words(> FROM words_moves
words(> WHERE gid = 3
words(> ORDER BY played DESC
words(> LIMIT 6) as skipscount;
sum
-----
6
(1 row)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Vick Khera 2016-09-06 15:51:22 Re: 2.5TB Migration from SATA to SSD disks - PostgreSQL 9.2
Previous Message Sándor Daku 2016-09-06 13:35:45 Re: Check if there 6 last records of same type without gaps