我想选择 5 篇最畅销的文章。
SELECT ID, shop, article_nr, count(*) as count
FROM table
GROUP BY shop, article_nr
ORDER BY count DESC
LIMIT 5
此查询的结果:
ID | shop | article_nr | count
--------------------------------------
71 | amazon | 123 | 280
98 | amazon | 223 | 170
35 | amazon | 323 | 99
7 | ebay | 456 | 71
11 | amazon | 789 | 49
4 | ebay | 032 | 10
如何在第二步中按“商店”列对结果进行分组(也许编辑查询)?
它应该看起来像这样(前 5 名中只有“一个”商店):
ID | shop | article_nr | count
--------------------------------------
71 | amazon | 123 | 280
7 | ebay | 456 | 71
.. | shop_x | ... | 55
.. | shop_y | ... | 40
.. | shop_z | ... | 37
有人能帮我吗?