Awesome, thanks!
Did not think to look in the virtual row documentation.
http://sequel.rubyforge.org/rdoc/files/doc/virtual_rows_rdoc.html

On Mar 25, 11:35 pm, Jeremy Evans <[email protected]> wrote:
> On Mar 25, 4:38 pm, rohit <[email protected]> wrote:
>
> > I am trying to convert some existing SQL to Sequel. Is there any way
> > to express the following select in Sequel without resorting to
> > literals?
>
> > select
> >     count(distinct case when x > 0 then y else null end) as z,
> >     count(distinct case when a > 0 then b else null end) as c,
> >     ...
>
> > rest of the query has several joins, where, group by that I can easily
> > express in Sequel.
>
> DB[:table].
>  select{[count(:distinct, {(x > 0)=>:y}.case(nil)){}.as(z),
>   count(:distinct, {(a > 0)=>b}.case(nil)){}.as(c)]}.sql
>
> SELECT count(DISTINCT (CASE WHEN (x > 0) THEN y ELSE NULL END)) AS z,
>        count(DISTINCT (CASE WHEN (a > 0) THEN b ELSE NULL END)) AS c
> FROM table
>
> 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.

Reply via email to