Gary Sieling

RethinkDB: Average example

You can easily get the average of values in a table in RethinkDB:

r.db('test')
 .table('salaries')
 .avg('salary')

If you want to do a GROUP BY as well, you’ll need to do a little more effort:

r.db('test')
 .table('salaries')
 .group('role')
 .avg('salary')
 .ungroup()
 .map(
    {Title: r.row('group'), 
     Amount: r.row('reduction')})

 

group
reduction
1
null
80600
2
Designer
72333.33333333333
3
Manager
106250
Exit mobile version