<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>h365info</author_name>
  <author_url>https://blog.hatena.ne.jp/h365info/</author_url>
  <blog_title>h365info's blog</blog_title>
  <blog_url>https://h365info.hatenablog.com/</blog_url>
  <categories>
    <anon>h365</anon>
    <anon>アダルト</anon>
    <anon>Rails</anon>
  </categories>
  <description>Rails4 で group by して count を取りたい時にこんなふうに書けます。 本に対してレビューが書かれていて、本ごとのレビュー件数を取りたい場合は Review.group(:book_id).order('count_all desc').count こんなふうに書くと (0.3ms) SELECT COUNT(*) AS count_all, book_id AS book_id FROM `reviews` GROUP BY book_id ORDER BY count_all desc =&gt; {588=&gt;5, 589=&gt;2, 590=&gt;1, 591=&gt;0, 592=&gt;4…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fh365info.hatenablog.com%2Fentry%2F2014%2F02%2F05%2F174950&quot; title=&quot;Rails で group by して count を取りたい時のイディオム - h365info&amp;#39;s blog&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2014-02-05 17:49:50</published>
  <title>Rails で group by して count を取りたい時のイディオム</title>
  <type>rich</type>
  <url>https://h365info.hatenablog.com/entry/2014/02/05/174950</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
