I'm trying to solve weather observation 20 from HackerRank using MYSQL and I've written the following code
SET @row1 = 0, @row2 = 0;
SELECT IF(COUNT(LAT_N) MOD 2 = 0,
-- Ture clasue
(SELECT ROUND(t.LAT_N,4)
FROM (SELECT station.LAT_N, @row1:= @row1 + 1 AS row1 FROM station GROUP BY station.LAT_N) AS t
WHERE t.row1 = ROUND(COUNT(t.row1) DIV 2,0)
),
-- False Clause
(SELECT ROUND(AVG(t.LAT_N),4)
FROM (SELECT station.LAT_N, @row1:= @row1 + 1 AS row1, @row2:= COUNT(LAT_N) - 1 AS row2 FROM station GROUP BY station.LAT_N) AS t
WHERE t.row1 = ROUND(COUNT(t.row1) DIV 2,0) - 1
OR
t.row2 = ROUND(COUNT(t.row2) DIV 2,0) + 1
)
)
FROM station;
but i'm getting this error
ERROR 1111 (HY000) at line 3: Invalid use of group function
can you please help me rectify.