Last active
August 29, 2015 14:23
-
-
Save blueset/41a5563d2b5b482a0139 to your computer and use it in GitHub Desktop.
Github Pastebin
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 title, content, category, pub_time | |
FROM news | |
WHERE ( | |
SELECT count(*) FROM news AS f | |
WHERE f.category = news.category AND f.pub_time <= news.pub_time | |
) <= 2; | |
# Via http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment