On May 4, 9:15 am, Eric <[email protected]> wrote:
> I can write the following sqlite query, how can I use sequel to do the
> same thing?  What stumps me is the CASE statement in the ORDER BY
> clause.  I am trying to get a list of people in this group and have
> supervisor/manager listed first, then order by last name, first name
> ignoring case.
>
> SELECT
>   A.login,
>   A.f_name,
>   A.l_name,
>   A.type,
>   V.name AS vendor,
>   A.lastlogin
> FROM
>   accounts A
>   LEFT OUTER JOIN vendors V
>     ON ( A.vendor_id = V.id )
> WHERE
>   A.`group` = 'SBC'
> ORDER BY
>   CASE WHEN A.type = 'supervisor' or
>             A.type = 'manager'
>         THEN 1
>   ELSE 2
>   END,
>   A.l_name COLLATE NOCASE,
>   A.f_name COLLATE NOCASE;

  DB[:accounts___A].
  left_outer_join(:vendors___V, :id=>:vendor_id).
  select
(:A__login, :A__f_name, :A__l_name, :A__type, :V__name___vendor, :A__lastlogin).
  filter(:A__group=>'SBC').
  order({{'supervisor'=>:A__type, 'manager'=>:A__type}.sql_or=>1}.case
(2), 'A.l_name COLLATE NOCASE'.lit, 'A.f_name COLLATE NOCASE'.lit)

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