Created
October 6, 2017 07:36
-
-
Save dmitry-udod/0843685b8235a0692403126e5d300e4a to your computer and use it in GitHub Desktop.
GROUP BY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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