title: Rails find_by_sql issue
body: <p>I have the following call in my RoR script:</p>
  
  <pre><code>Foo.where("event = 'Login'").group('user_id').order('user_id ASC').count()
  </code></pre>
  
  <p>This gives me a list of all users and how much they have logged in in the form of:</p>
  
  <pre><code>&lt;userid1&gt; =&gt; &lt;count&gt;, &lt;userid2&gt; =&gt; &lt;count&gt;, ...}
  </code></pre>
  
  <p>This is great and very close to what I wan but I've been unable to convince it to sort by the count of logins instead, what I'd really like to have it do. There is also a column that has some info about the login session in the form of a character delimited string. I'd like to get at certain parts of that information.</p>
  
  <p>To achieve this I've tried using find_by_sql and when I make the following call:</p>
  
  <pre><code>Foo.find_by_sql("SELECT userid, COUNT(*) AS number, SUBSTRING_INDEX(stuff, ',', 1) AS info FROM &lt;table&gt; WHERE event = 'Login' GROUP BY userid")
  </code></pre>
  
  <p>What I get is a ilst of Foo entries that contain the userids but not the count or the info. When I run this in the MySQL workbench it works like a charm. Is there something else I need to do to get this to work? Also, would there be a way to just do this using Foo.select or Foo.where? Thanks.</p>
  
  <p><strong>Update</strong> I have also tried this format, as demonstrated <a href="https://stackoverflow.com/questions/499767/ruby-on-rails-count-and-group">here</a>:</p>
  
  <pre><code>Foo.find(:all, :select =&gt; 'count(*) count, userid', :group =&gt;'userid')
  </code></pre>
  
  <p>But this too merely responds with the userids and does not spit out the count.</p>
  
  <p><strong>Update 2</strong> Looking at the output a bit more i can see now that when i do the find_by_fql call everything is being found in the correct way and even being sorted. It just isn't actually selecting the COUNT(*) or the SUBSTRING_INDEX.</p>
  
  <p><strong>Update 3</strong> I also tried out <a href="https://stackoverflow.com/questions/3057166/convert-sql-query-to-ruby-help">this</a> SO tip but when I tell it:</p>
  
  <pre><code>Foo.find(:all, :select =&gt; 'userid, count(*) as cnt', :group =&gt; 'userid')
  </code></pre>
  
  <p>It doesn't print or find anything related to the var cnt. I'm totally baffled here because I've seen more than one example now that does it this ^^ way and I've yet to get it to succeed.</p>