Quick reminder for myself of how to do a nested MySQL query with the nested statement in the parent where clause:
12345678910$sql = <<<SQL
SELECT id
FROM invoices as Invoice
WHERE id NOT IN (
SELECT parent_id
FROM invoices
WHERE parent_id > 0
GROUP BY parent_id
) AND billing_start <= ‘$end’
SQL;