I have the following table structure:
From which you want to take the percentage of the value that comes in the loans column grouped by number. of cuit.
I have tried this but in all cases 100% comes to me
SELECT
cdd.NumeroIdentificacion ,
cdd.Prestamos ,
CAST(REPLACE(cdd.Prestamos,',','.') AS FLOAT) * 100 /( SELECT
SUM(CAST(REPLACE(cdd.Prestamos,',','.') AS FLOAT))
FROM
CentralDeDeudores AS a
WHERE
a.NumeroIdentificacion = cdd.NumeroIdentificacion
GROUP BY
a.NumeroIdentificacion
) AS porcentaje
FROM
CentralDeDeudores cdd
GROUP BY
cdd.NumeroIdentificacion,cdd.Prestamos