On Monday, September 15, 2014 1:57:17 AM UTC-7, Hiroyuki Sato wrote:
>
> Hello members.
>
> My goal 
> I would like to execute the following sql with sequel.
>
> select path, max(mtime) as mtime, type from (
>
>   select path, mtime, 'server' as 'type'
>     from hoge
>    union 
>   select path, mtime, 'client' as 'type'
>     from fuga
> ) as tmp    
> group by path;
>
>
>
First, your SQL is not standard SQL as you are selecting non-aggregate 
expressions that you are not grouping by.  You probably want to group by 
path and type, or not select type.  I'm going to assume you want to group 
by path and type. It's also nonstandard to use a string instead of a 
identifier as an alias, but that's just a syntax issue.  Anyway, here's how 
you could represent the query using the Sequel DSL:

ds = DB.select(:path, :mtime)

ds.select_append(Sequel.as('server', :type)).from(:hoge).
  union(ds.select_append(Sequel.as('client', :type)).from(:fuga), 
:alias=>:tmp).
  select_group(:path, :type).
  select_append{max(:mtime).as(:mtime)}
 
Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to