Skip to content

Instantly share code, notes, and snippets.

@veapon
Created March 1, 2015 09:33
Show Gist options
  • Save veapon/15175446c8edc7c06cd0 to your computer and use it in GitHub Desktop.
Save veapon/15175446c8edc7c06cd0 to your computer and use it in GitHub Desktop.
按分组取最大
#按name分组取最大的两个(N个)val
select a.* from tb a where 2 > (select count(*) from tb where name = a.name and val > a.val ) order by a.name,a.val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment