| From: | Andreas Kretschmer <akretschmer(at)spamfence(dot)net> |
|---|---|
| To: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: Keeping top N records of a group |
| Date: | 2016-05-14 12:34:34 |
| Message-ID: | 20160514123434.GA28259@tux |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Alex Magnum <magnum11200(at)gmail(dot)com> wrote:
> Hi,
> i want to archive data and am looking for a query to replace a rather slow
> function i am currently using.
>
> The idea is that for every sym and doc_key I want to keep the records of the
> top 2 sources. Eg. in below table I want to archive
sounds like a case for window-functions here (maybe row_number() or
rank()), please read that for the start:
http://stackoverflow.com/questions/7613785/postgresql-top-n-entries-per-item-in-same-table
Regards, Andreas Kretschmer
--
Andreas Kretschmer
http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nicolas Paris | 2016-05-14 13:47:07 | Re: [SPAM] COPY command & binary format |
| Previous Message | Alex Magnum | 2016-05-14 11:33:29 | Keeping top N records of a group |