Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
-- 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;