On Thursday, November 5, 2015 at 3:14:31 AM UTC-8, Hiroyuki Sato wrote:
>
> Hello
>
> Could you tell me how to write ``like s.col1 || '%'`` join statement with 
> sequel?
>
> I would like to write following query with sequel.
> I wrote it except ``like join`` statement. 
>
> * DB: PostgreSQL 9.4.5
> * Sequel: 4.28.0
>
> Thank you for your advice.
>
>  SELECT col1, col2,count(*)
>    FROM ( SELECT s.col1,col2
>             FROM data_table1 l,
>                  rel_table s
>            WHERE l.path like s.col1 || '%'
>         UNION ALL
>        SELECT s.col1,col2
>          FROM data_table2 l,
>               rel_table s
>         WHERE l.path like s.col1 || '%'
>   ) as test GROUP BY col1,col2;
>
>
>
> db[:data_table1].select(:col1,:col2)
>   .union(db[:data_table2].select(:col1,:col2),:all=>true)
>   .group_and_count(:col1,:col2) 
>

db[:data_table1___l, :rel_table___s].select(:s__col1,:col2).
  where(Sequel.like(:l__path, Sequel.join([:s__col1, '%']))).
  union(db[:data_table2___l, 
:rel_table___s].select(:s__col1,:col2).where(Sequel.like(:l__path, 
Sequel.join([:s__col1, 
'%']))),:all=>true).
  group_and_count(:col1,:col2) 

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