On Wednesday, April 15, 2015 at 6:44:13 AM UTC-7, Andrew Burleson wrote:
>
> I've got a dataset, properties, which have square footage. I'd like to do
> a group and count by all square footages rounded to the nearest 100. I
> tried this:
>
> Property.exclude(square_footage: nil).select{ ciel(square_footage / 100) *
> 100 }.group_and_count(:square_footage)
>
> This executes fine but the expression doesn't seem to be used. The
> resulting SQL is:
>
> "SELECT \"square_footage\", count(*) AS \"count\" FROM \"properties\"
> WHERE (\"square_footage\" IS NOT NULL) GROUP BY \"square_footage\""
>
> What's the recommended way to accomplish this sort of thing? (group and
> count an expression result)
>
group_and_count calls select. You probably want:
Property.exclude(square_footage: nil).group_and_count((ciel(square_footage /
100) * 100).as(:square_footage))
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.