On Nov 15, 1:46 pm, Aman Gupta <[email protected]> wrote:
> On Sun, Nov 15, 2009 at 1:45 PM, André Allavena
> > What I need is
> > SELECT col3, sum((col1 - col2)) FROM foo GROUP BY col3"
> > otherwise, I don't know what sums corresponds to what.
>
> DB[:foo].select(:col3, :sum[:col1-:col2] => :val).group_by(:col3)
Note that that doesn't work on ruby 1.9. I'd recommend one of the
following:
DB[:foo].select(:col3, :sum.sql_function(:col1-:col2).as
(:val)).group_by(:col3)
# or
DB[:foo].select{[col3, sum(col1-col2).as(val)]}.group_by(:col3)
# or
DB[:foo].select(:col3){sum(col1-col2).as(val)}.group_by(:col3)
Jeremy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---