🕵️♀️ Task
You can calculate the average value in a particular column within a collection with .average. It returns a single value (Integer or Float).
LevelUp
0.0% complete
LevelUp
0.0% complete
| id | title | year | duration | description | image | director_id |
|---|
| id | name | dob | bio | image |
|---|
| id | name | dob | bio | image |
|---|---|---|---|---|
| 325 | Dooley Wilson | 1886-04-03 | "You must remember this, a ... | http://ia.media-imdb.com/im... |
| 326 | Joy Page | 1924-11-09 | Actress Joy Page (nee Joy C... | http://ia.media-imdb.com/im... |
| 327 | John Qualen | 1899-12-08 | One of the best and most fa... | http://ia.media-imdb.com/im... |
| 328 | Leonid Kinskey | 1903-04-18 | Leonid Kinskey, originally ... | |
| 331 | Gabriel Byrne | 1950-05-12 | Byrne was the first of six ... | http://ia.media-imdb.com/im... |
| 332 | Benicio Del Toro | 1967-02-19 | Benicio Del Toro emerged in... | http://ia.media-imdb.com/im... |
| 333 | Kevin Pollak | 1957-10-30 | Born in San Francisco in 19... | http://ia.media-imdb.com/im... |
| 334 | Kevin Spacey | 1959-07-26 | As enigmatic as he is talen... | http://ia.media-imdb.com/im... |
| id | actor_id | movie_id | name |
|---|---|---|---|
| 328 | 291 | 23 | Clarice Starling |
| 329 | 292 | 23 | FBI Instructor |
| 330 | 293 | 23 | Ardelia Mapp |
| 331 | 294 | 23 | Agent Burroughs |
| 332 | 295 | 23 | Jack Crawford |
| 333 | 296 | 23 | Dr. Frederick Chilton |
| 334 | 297 | 23 | Barney |
| 335 | 298 | 23 | Friendly Psychopath |
Calculate the average age for all users
User.all.average(:age)
=> 27
Calculate the average price for all dishes
Dish.all.average(:price)
=> 5.69