Trying to order a list of records by each type with the limit of 5 records per type.
For example:
I have 25 different GICS code such as 2050, 4010, 2540 and so on. And each GICS code is a different type of Industry, such as 2050 is bank, and 4010 is automobile, and 2540 is cosmetics.
Now each GICS code are assigned to multiple company names and are given a score. I want to be able to select the bottom 5 companies from each GICS code.
Is it possible? or do I need multiple sql?
Below is my SQL:
select g.4digits, c.company_name, os.* from overall_scores os
join company c
on c.company_id = os.company_id
join gics g
on g.company_id = c.company_id
where g.4digits in ((2550), (4010), (2540))
and os.overall_score <> 'NA'
and os.overall_score <> 'NaN'
order by os.overall_score asc limit 5;