Вам не нужно различать группу по
Вам нужны все столбцы, не включенные в функцию агрегации, упомянутые в группе как
SELECT
invoice.CustomerRef_FullName AS [Name Invoice],
receivepayment.CustomerRef_FullName AS [Name RP],
invoice.RefNumber AS Invoice#,
receivepayment.RefNumber AS Expr1,
invoice.AppliedAmount,
invoice.BalanceRemaining,
MIN(receivepayment.TotalAmount),
invoice.TimeCreated
FROM receivepayment
INNER JOIN invoice ON receivepayment.CustomerRef_FullName = invoice.CustomerRef_FullName
GROUP BY invoice.CustomerRef_FullNam ,
receivepayment.CustomerRef_FullName ,
invoice.RefNumber ,
receivepayment.RefNumber,
invoice.AppliedAmount,
invoice.BalanceRemaining,
invoice.TimeCreated
, или для получения всех нужных столбцовподзапрос или объедините значение min с соответствующей строкой
SELECT
invoice.CustomerRef_FullName AS [Name Invoice],
receivepayment.CustomerRef_FullName AS [Name RP],
invoice.RefNumber AS Invoice#,
invoice.AppliedAmount,
invoice.BalanceRemaining,
invoice.TimeCreated
FROM receivepayment
INNER JOIN invoice ON receivepayment.CustomerRef_FullName = invoice.CustomerRef_FullName
INNER JOIN (
SELECT
receivepayment.RefNumber AS Expr1,
MIN(receivepayment.TotalAmount) min_tot,
invoice.TimeCreated
FROM receivepayment
INNER JOIN invoice ON receivepayment.CustomerRef_FullName = invoice.CustomerRef_FullName
GROUP BY receivepayment.RefNumber;
) t on t.min_tod = receivepayment.TotalAmount
AND receivepayment.RefNumber = t.Expr1