Reputation: 2982
I have multiples tables with Names and Ages like this:
| Name | Age |
------------------
| Carlos | 25 |
| Mauricio | 28 |
| Cesar | 19 |
| Hernan | 7 |
And I need to retrieve all the names that are above the average Age. I tried
select Name from Table1 where Age > avg(Age)
but I found that the where clause does not work with aggregate functions, so I tried
select Name from Table 1 having Age > avg(Age)
But it does not work either.
Upvotes: 0
Views: 476
Reputation: 26876
You can do it with following query:
select Name from Table1 where Age > (select avg(Age) from Table1)
Upvotes: 3