{"id":2470,"date":"2015-07-21T03:18:01","date_gmt":"2015-07-21T03:18:01","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=2470"},"modified":"2015-07-21T03:18:01","modified_gmt":"2015-07-21T03:18:01","slug":"executing-a-group-by-in-rethinkdb","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/executing-a-group-by-in-rethinkdb\/","title":{"rendered":"Executing a &#8220;GROUP BY&#8221; in RethinkDB"},"content":{"rendered":"<p>Because RethinkDB uses a map-reduce architecture underneath, the syntax for &#8216;group by&#8217; is a little different than you might expect compared to SQL.<\/p>\n<pre lang=\"Javascript\">\nr.db('performance')\n .table('query_timings')\n .pluck('Query', 'Duration')\n .group('Query')\n .sum('Duration')\n<\/pre>\n<p>The interesting effect of this is that even though you specify only &#8216;Duration&#8217; in the sum, you get the grouping fields back as well. If you remove &#8216;sum&#8217;, you&#8217;ll get all the rows in each group in an array, which I imagine would be pretty handy for a lot of React-based applications.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Because RethinkDB uses a map-reduce architecture underneath, the syntax for &#8216;group by&#8217; is a little different than you might expect compared to SQL. r.db(&#8216;performance&#8217;) .table(&#8216;query_timings&#8217;) .pluck(&#8216;Query&#8217;, &#8216;Duration&#8217;) .group(&#8216;Query&#8217;) .sum(&#8216;Duration&#8217;) The interesting effect of this is that even though you specify only &#8216;Duration&#8217; in the sum, you get the grouping fields back as well. If you &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/executing-a-group-by-in-rethinkdb\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Executing a &#8220;GROUP BY&#8221; in RethinkDB&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[157,160,302,462,466,523],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/2470"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=2470"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/2470\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=2470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=2470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=2470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}