filter, sum and div in rethinkdb query -
how can join these 2 query ... mean ctr amount of time...i have tried different way solve couldn't find way write query in rethinkndb...
**r.expr({total_page_position:r.table('test_pagol')('position').sum(), total_page_load: r.table('test_pagol')('page').sum()}).merge({crt: r.row('total_page_load').div(r.row('total_page_position'))** **r.table("test_pagol").filter( (r.row["timestamp"] >= 1429617902988) & (r.row["timestamp"] >= 1429617922119))**
you can use map
, reduce
command that:
r.table("test_pagol").filter( r.row("timestamp").ge(1429617902988) .and(r.row("timestamp").le(1429617922119)) ).map({ 'total_page_position': r.row('position'), 'total_page_load': r.row('page') }).reduce(function(left, right) { return { 'total_page_position': left('total_page_position').add(right('total_page_position')), 'total_page_load': left('total_page_load').add(right('total_page_load')) } }).merge({ 'crt': r.row('total_page_load').div(r.row('total_page_position')) })
more information on map
: http://www.rethinkdb.com/api/javascript/map/ more information on reduce
: http://www.rethinkdb.com/api/javascript/reduce/
(an unrelated note: if want make query faster, create index on timestamp
field , replace filter
between(1429617902988, 1429617922119, {index: "timestamp", rightbound="closed"})
, see http://www.rethinkdb.com/api/javascript/between/ )
Comments
Post a Comment