Hello Jeremy,

I successfully managed to write this by myself. Please skip this question. 
I have another question that I will post later.

Thanks,
Dennis.

On Sunday, May 10, 2020 at 6:12:30 AM UTC+3, Dennis O'Connell wrote:
>
> Hello,
>
> How can I use WITH and UNION ALL in single query? I'm trying to do this query:
>
> WITH united as (
>   SELECT email, full_name FROM contacts
>   UNION ALL
>   SELECT sender->>'email', sender->>'name' FROM emails
> )
>
> SELECT
>   email,
>   full_name,
>   count(*) count,
>   row_number() over (partition by email) rk
>
> FROM united
> GROUP BY 1, 2;
>
> How can i write this in Sequel?
>
> What I've tried so far (and failed) something like:
>
> Contact.from { united.as(:s) }
> .select_all(:s) .where { s[:rk] =~ 1 } 
> .with(:summary_senders, Email.from { emails.as(:d) }
> .where(name: "john")
> .union(Contact.from { contacts.as(:d2) })).order(Sequel.desc(:count)).sql
>
>
>
>
> Thanks,
>
> Dennis
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/bd6278a1-7bcd-48a1-b816-06a05f9ab1cc%40googlegroups.com.

Reply via email to