我需要显示从我的数据库中购买的前5个产品
前5个产品
banana
apple
orange
mango
egg
我有一个显示所有内容的表格,如果该行重复超过2,那么它将是最佳产品。我该怎么做?
答案 0 :(得分:3)
SELECT name FROM products GROUP BY name ORDER BY COUNT(name) DESC LIMIT 5;
最终:
SELECT name FROM products GROUP BY name HAVING count(name) > 2 ORDER BY COUNT(name) DESC LIMIT 5;