I'm on MySQL 5.7 and have a dataset as the table, `bundles`.

| bundle\_id | single\_amount | item\_count |
| --- | --- | --- |
| 1 | 100 | 1 |
| 2 | 20 | 3 |
| 3 | 15 | 2 |

SQL Fiddle: <http://sqlfiddle.com/#!9/823c91/1/0>

e.g. The table means that for bundle1, a customer bought one item that is $100 and another customer bought 3 items that the individual one is $20.

I want to get the top n data by individual item, not by a bundle. The straightforward idea is to flatten the data as the table below.

| single\_amount | item\_count |
| --- | --- |
| 100 | 1 |
| 20 | 3 |
| 20 | 3 |
| 20 | 3 |
| 15 | 2 |
| 15 | 2 |

It's easy to do it on service but considering the potential size of the dataset, is there a way to do it on MySQL side?