Problems wording a GROUP BY ranked query - Mailing list pgsql-novice

From Ila B.
Subject Problems wording a GROUP BY ranked query
Date
Msg-id 5C9EA2E4-4338-4E8D-AD3C-6356CDADE366@gmail.com
Whole thread Raw
List pgsql-novice
Hello,

I have a table which looks like this:
Username | prescription_code | birth_date | prescription_date

I have 5 age classifications: 0-14, 15-24, 25-44, 45-64 and 65+.
I want to extract for each year (using date_part) the three most common prescriptions (maximum count) for each age
classification(using just the date subtraction and converting years in days). 

I would like results to be in the same table, to export it as CSV in an easy way using the IDE (PGAdmin 4, version 3.5
onWindows). I thought about using UNION and CTEs to extract rank, but that would mean writing 5 queries with CTEs. Is
therea better way? 

Thanks,
Ilaria

pgsql-novice by date:

Previous
From: Andreas Kretschmer
Date:
Subject: Re: Elegant way to insert of some value in some tables in shortinstruction
Next
From: Gavin M2301
Date:
Subject: error installing on mingw