0

I'm trying to solve this problem in Hackerrand

The problem asks for the median in a specific column

my code:

SET @VAE = (SELECT COUNT(*) FROM STATION);
SET @VAE1 = ROUND(@VAE/2)-1;
SELECT LAT_N FROM STATION ORDER BY LAT_N LIMIT @VAE1;

But I get syntax error.

When I write the query as following it runs ok, but I don't want it in such way

SET @VAE = (SELECT COUNT(*) FROM STATION);
SET @VAE1 = ROUND(@VAE/2)-1;
SELECT LAT_N FROM STATION ORDER BY LAT_N LIMIT 5;

what is the problem ?

1 Answer 1

-1

Use procedure to execute we cannot use the variables in normal offset in limit but we can use variables in procedure

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.