agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Ila B. <ilaria.battiston@gmail.com>
To: pgsql-sql@lists.postgresql.org
Subject: Top 3 values for each group in PGSQL
Date: Fri, 1 Mar 2019 11:51:24 +0100
Message-ID: <67FB61BF-CF8F-440E-B4C5-B6F72D61A9C7@gmail.com> (raw)

Hello,

I’m working on a health database and I’m trying to extract the most popular prescription codes from a custom table I structured like this:

Year - Code - Count(code)

I want to extract the 3 codes with maximum count for each year. I know I should be using rank() but I don’t really understand how this works.
I am using pgAdmin4 version 3.5 with PostgreSQL 10.6 on Windows 10 Pro and no permission to update.

Thank you in advance,
Ilaria



view thread (4+ messages)  latest in thread

Message-ID: <67FB61BF-CF8F-440E-B4C5-B6F72D61A9C7@gmail.com>
Permalink:  ../67FB61BF-CF8F-440E-B4C5-B6F72D61A9C7@gmail.com/
Also on:    postgresql.org/message-id/67FB61BF-CF8F-440E-B4C5-B6F72D61A9C7@gmail.com

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ilaria.battiston@gmail.com, pgsql-sql@lists.postgresql.org
  Subject: Re: Top 3 values for each group in PGSQL
  In-Reply-To: <67FB61BF-CF8F-440E-B4C5-B6F72D61A9C7@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox