Re: query on query

From: Luca Ferrari <fluca1978(at)infinito(dot)it>
To: Jayadevan M <jayadevan(dot)maymala(at)ibsplc(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: query on query
Date: 2013-07-05 06:35:22
Message-ID: CAKoxK+45XnSM+XQSEq8vb1owCppQ5v=gnG3CwHxX4E0TTVcboA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Jul 5, 2013 at 5:09 AM, Jayadevan M
<jayadevan(dot)maymala(at)ibsplc(dot)com> wrote:

>
> So each student may get counted many times, someone with 99 will be counted
> 10 times. Possible to do this with a fat query? The table will have many
> thousands of records.
>

Not sure I got the point, but I guess this is a good candidate for a CTE:

WITH RECURSIVE t(n) AS (
VALUES (10)
UNION ALL
SELECT n+10 FROM t WHERE n < 50
)
select count(*), t.n from m, t where mark > t.n group by t.n;

Luca

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jayadevan M 2013-07-05 07:02:55 Re: query on query
Previous Message guxiaobo1982 2013-07-05 05:11:07 回复: [GENERAL] Can't create plpython language