Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Average height of building

Tags:

sql

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

I have tried:

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

But it is not working, any ideas? :)


1 Answers

Have a subquery to get the average mountain height:

SELECT Name FROM mountain 
WHERE (select AVG(Height) from mountain) BETWEEN Height - 100 and Height + 100
like image 126
jarlh Avatar answered Dec 12 '25 03:12

jarlh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!