0
Hypothetically, having 8 columns in an X table, 4 of these columns store an average:
AVG(colunaN)
And the other four store the amount of elements of that average
COUNT(column)
In a query I’m trying to get the highest average of these 4, so I use the function:
GREATEST(coluna1,coluna2,coluna3,coluna4) AS maior_media
How can I do to identify which column was selected as the largest in "GREATEST" to return your
COUNT(colunaSelecionadaPorGreatest)
Which in the above situation is stored in one of the other 4 columns.
Wouldn’t it be more practical to work with rows and not columns? Then just a GROUP BY/MAX.
– anonimo
well, in the architecture of this college project of mine, I defined that it is better that I update the averages and counts in a separate table, to avoid making these calculations for each item I will show in the system, so it updates this data periodically using cronjobs.
– shelldude
Then do a gambit using CASE / WHEN.
– anonimo