create table pizzas as
  select "Pizzahhh" as name, 12 as open, 15 as close union
  select "La Val's"        , 11        , 22          union
  select "Sliver"          , 11        , 20          union
  select "Cheeseboard"     , 16        , 23          union
  select "Emilia's"        , 13        , 18;

create table meals as
  select "breakfast" as meal, 11 as time union
  select "lunch"            , 13         union
  select "dinner"           , 19         union
  select "snack"            , 22;

-- Two meals at the same place
create table double as
  select a.meal, b.meal, name
         from meals as a, meals as b, pizzas
         where open <= a.time and a.time <= close and
               open <= b.time and b.time <= close and
               b.time > a.time + 6;


-- Pizza options for every meal
create table options as
  with
    lists(meal, time, names, last, n) as (
      select meal, time, name, name, 1
             from pizzas, meals
             where open <= time and time <= close union
      select meal, time, names || ", " || name, name, n+1
             from lists, pizzas
             where open <= time and time <= close and name > last
    )
  select meal, max(n), names from lists group by meal order by time;


