Similar to the Advent of Code, the Hanukkah of Data (archive) was released in December 2022.

I don’t have time to do that during the holidays, so January 2023 it is for me.

1. Plan of attack

I’m looking for:

  1. a person who bought something not long after our previous person

  2. a thing that is identical except in colour

  3. because they talked in the queue, they probably followed each other → the exact next order

  4. a guy

2. Implementation

This time, everything should be doable in SQL right away via DBeaver.

create view next_orders as
  o.orderid + 1 as orderid
  orders o
join customers c on
  o.customerid = c.customerid
where = 'Previous Person';

  orders o
join orders_items oi on
  oi.orderid = o.orderid
join products p on
  p.sku = oi.sku
join customers c on
  c.customerid = o.customerid
join next_orders no on
  no.orderid = o.orderid;

3. Result

This finds all the people who ordered right after our previous person for all times.

There are only 29 rows in 900 ms, and even fewer about objects with colours bought by people whose name are male.

The right result is there.

Time to solve: 16 minutes.