As far as I get it, the following code will help you:
,min(InvoiceDate) as InvoiceDate
,'1' as Flg
Group by OrderId;
Where the minimum date is occurs by OrderId, the Flg columns contains 1 else null or missing value.