fix postgres SQL group issue