0

I want to perform this and get the divided result as output, but I get an error.

I have tried this RethinkDB query:

r.object(
    "total_page_loads",
    r.table("test_db")("page_loads").sum(),
  "total_clicks",
    r.table("test_db")("clicks").sum(),
  'aggre',
  r.expr('total_page_loads').div('total_clicks')
)
Sébastien
  • 11,860
  • 11
  • 58
  • 78
Istiak Mahmood
  • 2,330
  • 8
  • 31
  • 73

1 Answers1

0

The trick is to get the two counts first, and to divide in a seperate step. You can use .merge for this:

r.expr({
    total_page_loads: r.table('test_db')('page_loads').sum(),
    total_clicks:     r.table('test_db')('clicks').sum()
}).merge({
    aggre: r.row('total_page_loads').div(r.row('total_clicks'))
})

Note that:

  • You can not refer to fields by only their name as a string. They must be wrapped in an r.row inside a command that maps over the table such as merge.
  • You can use an object literal (wrapped in r.expr) instead of r.object
Etienne Laurin
  • 6,731
  • 2
  • 27
  • 31
  • how can i implement it if i also want to implement "filter" for certain amount of time... i mean combine 2 query at the same time like .... – Istiak Mahmood Apr 29 '15 at 13:02