In fact, query is now like this:

SELECT DISTINCT ON (jj->>'email')  jj->>'email',  jj->>'name' , count(*) 
over(partition by jj->>'email' )
from emails
join lateral jsonb_array_elements(send_to) j(jj) on true
ORDER BY jj->>'email', id  desc



On Friday, May 24, 2019 at 12:55:01 PM UTC+3, xura wrote:
>
> Hi,
>
> Is it possible to write this query with Sequel?
>
>     SELECT DISTINCT ON (x.e->>'email')
>       x.e->>'email' as email,
>       x.e->>'name'  as name
>       FROM messages sr
>       CROSS JOIN LATERAL jsonb_array_elements(sr.receiver)  x (e)
>       ORDER BY x.e->>'email', id desc
>
> Or I use *with_sql?*
>
> Thanks!
>

-- 
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 https://groups.google.com/group/sequel-talk.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/c35baa5c-ff7e-4d80-ac38-10115e0665c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to