Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL Average height of mountain

I have a database with Mountains, with their names and heights. I want a query that gives me the names of the montains that differ less than 100 meters height from the average of all
mountains.

I have tried:

SELECT Name FROM mountain 
WHERE Height BETWEEN ABS((AVG(Height)) - 100) AND ABS(AVG(Height))

But it is not working, any ideas? 🙂

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need a subquery to get the average mountain height:

SELECT Name FROM mountain 
WHERE (select AVG(Height) from mountain) BETWEEN Height - 100 and Height + 100
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading