Skip to content

Instantly share code, notes, and snippets.

@GGrassiant
Created April 15, 2022 17:54
Show Gist options
  • Save GGrassiant/32a4ad671195f7748303e8802404cd5d to your computer and use it in GitHub Desktop.
Save GGrassiant/32a4ad671195f7748303e8802404cd5d to your computer and use it in GitHub Desktop.
SQL Group and SubQuery
with group_orders as (
SELECT customer_number, count(order_number) as numOfOrder
FROM orders
GROUP BY customer_number
)
SELECT customer_number
FROM orders
GROUP BY customer_number
HAVING count(order_number) = (SELECT MAX(numOfOrder) FROM group_orders)
#See https://leetcode.com/problems/customer-placing-the-largest-number-of-orders/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment