Skip to content

Instantly share code, notes, and snippets.

@dmitry-udod
Created October 6, 2017 07:36
Show Gist options
  • Save dmitry-udod/0843685b8235a0692403126e5d300e4a to your computer and use it in GitHub Desktop.
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