SELECT cias.NOMBRE, cias.CODIGO, year(datosexa.FECHARES) as anno, month(datosexa.FECHARES) as mes, sum(saldocli) as "Saldo Cliente", sum(saldocia) as "Saldo Cia"
FROM datosexa
Inner Join cias ON datosexa.CIA = cias.CODIGO 
where fechares between '2011-11-01' and '2012-01-31' and cias.CODIGO > 0
group by 2,3,4
order by 1,3,4
into outfile "/tmp/saldocias.txt";

