I’m working with an Airtable database that has a bunch of numeric columns (about 17 of them). I need to find the 5 largest values from all these columns combined and display them in a specific format.
Right now I can only get the maximum value using the MAX function, but I need something similar to Excel’s LARGE function to get the top 5 values. I tried different approaches but can’t figure out how to do this in Airtable.
In other databases I would use something like this approach:
SELECT data.*, results.*
FROM data_table CROSS JOIN LATERAL
(SELECT max(vals.value) FILTER (WHERE rank_num = 1) AS top_1,
max(vals.value) FILTER (WHERE rank_num = 2) AS top_2,
max(vals.value) FILTER (WHERE rank_num = 3) AS top_3,
max(vals.value) FILTER (WHERE rank_num = 4) AS top_4,
max(vals.value) FILTER (WHERE rank_num = 5) AS top_5
FROM (SELECT vals.value, row_number() OVER (ORDER BY value DESC) AS rank_num
FROM (VALUES (field_1), (field_2), (field_3)...
) vals(value)
) vals
) results;
But I’m stuck on how to implement something similar in Airtable. Any suggestions on how to achieve this?