Hanukkah of Data 2022: Puzzle 7
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:
a person who bought something not long after our previous person
a thing that is identical except in colour
because they talked in the queue, they probably followed each other → the exact next order
This time, everything should be doable in SQL right away via DBeaver.
create view next_orders as select o.orderid + 1 as orderid from orders o join customers c on o.customerid = c.customerid where c.name = 'Previous Person'; select c.name, c.phone, p."desc" from 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;
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.