Original query:

SELECT * from appointments_customers where appointment_id in (SELECT id FROM "appointments" WHERE "agenda_id" IN (3943,5699,1525,4006,3221,2858,1528,1514,4967,5698,5452,5969,2147,1512,5453) AND (("start_at" <= '2019-01-14T00:00:00.000+00:00' AND "end_at" >= '2019-01-01T00:00:00.000+00:00')));