title: Avoiding SQL injection with a range in the HAVING Clause
body: <p>How can I properly avoid SQL injection while taking advantage of Rails goodness. For example, this code:</p>
  <pre><code>Account.group(&quot;accounts.id&quot;).having(&quot;MIN(created_at)&quot;: 1.month.ago.all_month).first
  </code></pre>
  <p>Raises this exception:</p>
  <pre><code>Mysql2::Error: Unknown column 'accounts.MIN(created_at)' in 'having clause'
  </code></pre>
  <p>I could do it like this, but then I lose the beauty of the range:</p>
  <pre><code>Account.group(&quot;accounts.id&quot;).having(&quot;MIN(created_at) BETWEEN ? AND ?&quot;, 1.month.ago.beginning_of_month, 1.month.ago.end_of_month])
  </code></pre>