I have a working query from the report using min and max window function, but I need to pull the references of min and max. Here's the main query:
SELECT
company,
countryname,
dept,
unit,
score,
MAX(score) OVER(PARTITION BY company) AS max_comp_score,
--need reference countryname, dept, unit for this max score
MIN(score) OVER(PARTITION BY company) AS min_comp_score,
--need reference countryname, dept, unit for this min score
AVG(score) OVER(PARTITION BY company) AS avg_comp_score
FROM
tt.vw_Score_Report
The view is quite big (5 mil rows), so if I do sub-queries on min and max to pull their references from there, it takes ages to retrieve them.
What are the options to get those attributes to the query? Thought there could be some elegant way of solving that.