On Nov 26, 2009, at 7:20 PM, Aman Gupta wrote:
> On Thu, Nov 26, 2009 at 7:17 PM, Christer Nilsson
> <[email protected]> wrote:
>> 2009/11/26 Jeremy Evans <[email protected]>
>>> On Nov 26, 8:04 am, Christer Nilsson <[email protected]>
>>> wrote:
>>>> SELECT activityID, *sum*(hours) as hours FROM tbltime WHERE activityID
>>>> IN
>>>> (42,4711) *GROUP* BY activityID
>>> 
>>> TblTime.filter(:activityID => [42,4711]).group(:activityID).select
>>> {[activityID, sum(hours).as(hours)]}
>>> 
>>> Jeremy
>>> 
>> Is the part after .select a hash or a block?
>> And why are the column names not symbols?
>> The syntax is ok, I just wan't to understand what's going on.
> 
> It's a block. In 1.8 you can also do .select(:activityID, :sum[:hours]
> => :hours), but that won't work in 1.9.

Or, for 1.9 and not using the block syntax:

DB[:foo].filter(:a=>[1,2]).group(:a).select(:a, :sum.sql_function(:h).as(:h) 
).sql
#=> "SELECT a, sum(h) AS 'h' FROM foo WHERE (a IN (1, 2)) GROUP BY a"

--

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.


Reply via email to