Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含以下列的表格
Store_ID, Item_ID, Sales_Amount
我需要为每家商店检索两个最畅销的商品。有人对这个问题有想法或建议吗?
这应该工作
SELECT mytable.Store_ID, mytable.Sales_Amount FROM mytable LEFT JOIN mytable table2 ON mytable.Store_ID = table2.Store_ID AND mytable.Sales_Amount <= table2.Sales_Amount GROUP BY mytable.Store_ID, mytable.Sales_Amount HAVING COUNT(mytable.*) <= 2;