Skip to content

Instantly share code, notes, and snippets.

@dmitry-udod
Created October 6, 2017 07:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dmitry-udod/0843685b8235a0692403126e5d300e4a to your computer and use it in GitHub Desktop.
GROUP BY
select DISTINCT ON (t.orders) * from (select max(id) id, max(email), max(orders) as orders, campaign_id from coupons group by campaign_id ORDER BY orders DESC) as t ORDER BY t.orders DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment