From fb5cb7d85a147fd6ba7c421175a5df04e50f9b5f Mon Sep 17 00:00:00 2001 From: Santosh Gouda <100397695+sgouda0412@users.noreply.github.com> Date: Sat, 14 Jun 2025 19:25:31 +0530 Subject: [PATCH] Update customer-placing-the-largest-number-of-orders.sql --- ...ustomer-placing-the-largest-number-of-orders.sql | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/leetcode/easy/586-customer-placing-the-largest-number-of-orders/customer-placing-the-largest-number-of-orders.sql b/leetcode/easy/586-customer-placing-the-largest-number-of-orders/customer-placing-the-largest-number-of-orders.sql index 484453b..2b638cf 100644 --- a/leetcode/easy/586-customer-placing-the-largest-number-of-orders/customer-placing-the-largest-number-of-orders.sql +++ b/leetcode/easy/586-customer-placing-the-largest-number-of-orders/customer-placing-the-largest-number-of-orders.sql @@ -9,4 +9,15 @@ LIMIT 1 -- Why are subqueries bad? They're good for readability and often for interviewing. However, in real life subqueries increase the amount of scans taken from the original tables. -- From a performance tuning perspective, it's often a good idea to reduce the number of subqueries firing every second on the backend. --- For interviews, it's often a good idea to go with the subquery. \ No newline at end of file +-- For interviews, it's often a good idea to go with the subquery. + +WITH RankedCustomers AS ( + SELECT + customer_number, + DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS rank + FROM Orders + GROUP BY customer_number +) +SELECT customer_number +FROM RankedCustomers +WHERE rank = 1;