Leetcode Note: MySQL - Customer Placing the Largest Number of Orders
Customer Placing the Largest Number of Orders - LeetCode
https://leetcode.com/problems/customer-placing-the-largest-number-of-orders/
- MySQL で取り組んだメモ
所感
- Orders table から最も order_number の頻度が大きいレコードの customer_number を抽出する
- つまり、最も多く注文している customer を特定する
回答
Customer Placing the Largest Number of Orders - LeetCode https://leetcode.com/problems/customer-placing-the-largest-number-of-orders/solution/
SELECT customer_number FROM Orders GROUP BY customer_number ORDER BY COUNT(*) DESC LIMIT 1;
GROUP BY
で customer_number を集計ORDER BY COUNT(*) DESC
で出現回数を降順で取得LIMIT 1
で 1 レコードのみ取得