Skip to content

2084. Drop Type 1 Orders for Customers With Type 0 Orders 👍

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
WITH
  RankedOrders AS (
    SELECT
      *,
      RANK() OVER(PARTITION BY customer_id ORDER BY order_type) AS `rank`
    FROM Orders
  )
SELECT
  order_id,
  customer_id,
  order_type
FROM RankedOrders
WHERE `rank` = 1;