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:
>> > I'm *very* pleased with Sequel, but have one minor question:
>> >
>> > Is it possible to produce the following sql with Sequel?
>> >
>> > SELECT activityID, *sum*(hours) as hours FROM tbltime WHERE activityID
>> > IN
>> > (42,4711) *GROUP* BY activityID
>> >
>> > Trying TblTime.filter(:activityID =>
>> > [42,4711]).group(:activityD).sum(:hours)
>> >
>> > I got SELECT sum(hours) as hours FROM tbltime WHERE activityID IN
>> > (42,4711)
>> > GROUP BY activityID LIMIT 1
>> >
>> > which returns 1x1 cell instead of expected 2x2
>> >
>> > How do I use sum in .select ?
>> >
>>
>> TblTime.filter(:activityID => [42,4711]).group(:activityID).select
>> {[activityID, sum(hours).as(hours)]}
>>
>> Jeremy
>>
> Yes, it works!
>
> 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. In the block syntax, you don't
need symbols:

.select{ field_name }
.select{ [ field_one, field_two ] }
.select{ count(field_name) }

  Aman

>
> Christer
>
> --
>
> 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.
>

--

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