I got stuck in a scenario where I am selecting average of each column in a table. Now I want to find the top three of those columns.
here is my query:
SELECT AVG( `adventure` ) , AVG( `beach` ) , AVG( `culture` ) , AVG( `festival` ) , AVG( `food` ) , AVG( `fun` ) , AVG( `biking` ) , AVG( `ski` ) , AVG( `surf` ) , AVG( `family` ) , AVG( `couple` ) , AVG( `single` ) , AVG( `backpacker` )
FROM `ratings`
WHERE `reference_id`=4595
This query returns me average of each column. But I want to select top 3 averages only.
Thanks in advance!
I guess you need to normalized your table first but here’s a query that suits your needs,
By the way it returns two columns, the names of the column on where the average was calculated and the result of the average.