... shouldn't it also include a GROUP BY clause for the i.Batch_id column?! ...
pesky details! i suppose so.