- 1

Can't you also specify the query as: SELECT * FROM Zoo WHERE age > AVG(age) ?

2nd Jun 2019, 10:05 PM
Nyaniba
Nyaniba - avatar
2 Antworten
+ 6
(SQL tutorial > challenges > challenge 1 > question 7) No, you can't, because AVG() is an aggregate function that returns one value for all data sets in the table, whereas SELECT * selects single data sets. So you need two different queries, one "standard" and one aggregate query. If you want to want to find out which children in a class are older than the average age of the students, you can't find that out by just asking everyone for their age. You need to know all of their ages in order to calculate the average (aggregate function). Then you can look at each kid and check if they are over or under the average => two queries
3rd Jun 2019, 6:01 AM
Anna
Anna - avatar
+ 1
Okay. Thanks.
5th Jun 2019, 10:39 AM
Nyaniba
Nyaniba - avatar