mysql limit inside group?

后端 未结 8 759
粉色の甜心
粉色の甜心 2021-01-13 07:35

I want to limit the size of records inside a group, and here is my trial, how to do it right?

mysql> select * from accounts limit 5 group by type;
         


        
8条回答
  •  青春惊慌失措
    2021-01-13 07:41

    It appears you want to limit the number of rows returned within each group of your overall result set... this is difficult to do in a way that scales well. One technique is to perform N joins on the same table with the conditions such that the only rows that match are the top/bottom N that you want.

    this page may offer some additional insight into your solution... although returning the top 5 in each group is going to get ugly fast.

提交回复
热议问题