Você tem um erro de sintaxe no seu SQL próximo a 'GROUP BY S.id ORDER BY total DESC' na linha 1