Home  >  Article  >  Database  >  mysql常用_MySQL

mysql常用_MySQL

WBOY
WBOYOriginal
2016-06-01 13:06:58947browse

1、mysql 分组取前N记录

select present_price,userid from wx_goods a where 2 > (select count(*) from wx_goods where userid=a.userid and present_price>a.present_price) GROUP BY present_price ORDER BY userid,present_price desc

其中 GROUP BY present_price 是为了去除因比较值重复的情况发生

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn