🕵️♀️ Task
You can calculate the sum of values in a particular column within a collection with .sum. 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 |
|---|---|---|---|---|
| 311 | Woody Strode | 1914-07-25 | An athlete turned actor, St... | http://ia.media-imdb.com/im... |
| 312 | Jack Elam | 1920-11-13 | Colorful American character... | http://ia.media-imdb.com/im... |
| 313 | Keenan Wynn | 1916-07-27 | Character actor Keenan Wynn... | http://ia.media-imdb.com/im... |
| 314 | Frank Wolff | 1928-05-11 | Frank Wolff started his car... | |
| 321 | Sydney Greenstreet | 1879-12-27 | Sydney Greenstreet's father... | http://ia.media-imdb.com/im... |
| 322 | Peter Lorre | 1904-06-26 | As a youth Peter Lorre ran ... | http://ia.media-imdb.com/im... |
| 323 | S.Z. Sakall | 1883-02-02 | Hungarian-born S.Z. Sakall ... | http://ia.media-imdb.com/im... |
| 324 | Madeleine Lebeau | 1923-06-10 |
| id | actor_id | movie_id | name |
|---|---|---|---|
| 320 | 283 | 22 | Gluttony Victim |
| 321 | 284 | 22 | Dr. O'Neill |
| 322 | 285 | 22 | Coroner (as Reginald E. Cat... |
| 323 | 286 | 22 | Workman |
| 324 | 287 | 22 | Cab Driver |
| 325 | 288 | 22 | George, Library Night Guard |
| 326 | 289 | 22 | Library Guard (as Roscoe Da... |
| 327 | 290 | 22 | Library Guard |
Calculate the sum of ages for all users
User.all.sum(:age)
=> 4566
Calculate the sum of prices for all dishes
Dish.all.sum(:price)
=> 232