Skip to content
Quantoros

Return each orderid that has NO orderid + 1 following it, excluding the maximum id - these mark where gaps start.…

SQLLevel: AdvancedGaps, islands and streaks

Return each order_id that has NO order_id + 1 following it, excluding the maximum id - these mark where gaps start.

Table definitions (from the source exercise):

CREATE TABLE orders(order_id INTEGER PRIMARY KEY, customer_id INTEGER, order_date TEXT, amount REAL, rep_id INTEGER, discount REAL);
Hints
  • Define one output row and the source-table keys.
  • Check duplicates, NULLs and the order of filtering and aggregation.

Answer

This answer is part of mentoring

Advanced questions come with a full breakdown and a mock interview with a working quant researcher. The first call is free.

Source and licence: SQL Practice Lab — Ebrahim Sharifi · MIT

Related questions