Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzflO-0005bg-IP for pgsql-sql@arkaria.postgresql.org; Fri, 01 Mar 2019 10:51:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gzflM-00087e-Oh for pgsql-sql@arkaria.postgresql.org; Fri, 01 Mar 2019 10:51:32 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzflM-00087Q-Bp for pgsql-sql@lists.postgresql.org; Fri, 01 Mar 2019 10:51:32 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzflJ-0006fA-HZ for pgsql-sql@lists.postgresql.org; Fri, 01 Mar 2019 10:51:30 +0000 Received: by mail-wm1-x331.google.com with SMTP id z84so11784291wmg.4 for ; Fri, 01 Mar 2019 02:51:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=W0TI4u9CX3iV4UP92r9qHbyWuE4H7pfZd1z6gGaNZ+A=; b=vPnxzoqkhV1eHCJfsi0NICsHfwKf2JiypkR3Ja4aIpxfdqfnkpmJtCZFkd0gxFqSeH kZY4UifJqCjQroqymPBCmz77U/Xuk1wvdIs5z4VvYvu9Plytpjn62RlcdWzwOVoh363Y ATfFTUT4k2JIbDwISF1Sd/GCJ0+QU19+3WGfdH8HG8A8Cgp6xgNNOsCUkvOpjEoA+OKt l8xomoKiCUzGyqXv541p7pBxTG14vLjwNEF1oqyB66px3dTciHRG3ZpxsUjrnd653aoE guX/xDn86E8H8Rxxk/lBXn9WC20ijDfvFk7V+c6xkC43K686mZYlrtTkBjf1hOP29Q7N uDkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=W0TI4u9CX3iV4UP92r9qHbyWuE4H7pfZd1z6gGaNZ+A=; b=BymBzn1kY1shtxTMUN8DZ/IlfNKMiPOJuDCRwoEk/LgFm4pCX1I6Y/BsryyaNUl5Wu 2TjXvEkIlfqA91yoJw6TOdMDgM2OHQDJCmo2yRreBMfV8iTnu3Nv050echyFtM262/L5 +pYG1Adq3YPn97Z3ftXz2UVoI3W/wjgTcGSiH2TXUUGBWV4zpNXhV+jh3SAURGP8U9vQ cWSnj3YzkqJryaGCRjIXpWbhGjrddfpjgFpJw2zlKRSEOB4hvxT7hwECen3v4Vb9YgDA +GPQv76d0NiDSxz+5cGKxx6LnKcaDhbRAU5/3cs3Om8qJaU6xaD+zwKUmWVoxc89vGTF AhFA== X-Gm-Message-State: APjAAAXVuVFBSe5SWP3iXf96E6j2r+ENtnppEn41C2opbajtWEzKeXzR OmPWlxMEMPjbId8ghAQywrXuipp+cF3IuA== X-Google-Smtp-Source: APXvYqyUcf/WSdyHFQVdOoeNpZz0BGCHDNQ9Fl9jInwNwj57JIkO6db2/PElyRW66Miqx6OdRG3A+A== X-Received: by 2002:a1c:6045:: with SMTP id u66mr2461895wmb.133.1551437486758; Fri, 01 Mar 2019 02:51:26 -0800 (PST) Received: from [10.255.7.113] ([149.132.31.9]) by smtp.gmail.com with ESMTPSA id r15sm20123587wrt.37.2019.03.01.02.51.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Mar 2019 02:51:25 -0800 (PST) From: "Ila B." Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Subject: Top 3 values for each group in PGSQL Message-Id: <67FB61BF-CF8F-440E-B4C5-B6F72D61A9C7@gmail.com> Date: Fri, 1 Mar 2019 11:51:24 +0100 To: pgsql-sql@lists.postgresql.org X-Mailer: Apple Mail (2.3445.102.3) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello, I=E2=80=99m working on a health database and I=E2=80=99m 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=E2=80=99t 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=