I need to count the duplicate values of a field. I have the following Query:
SELECT [GRADO DE RIESGO POR CREDITO],COUNT([GRADO DE RIESGO POR CREDITO]) AS ABC
FROM FINREP.dbo.[CALIFICACION_SOFOM.CALIFICACION]
GROUP BY [GRADO DE RIESGO POR CREDITO]
Which gives me this output:
Once this is done, I am looking to do an "UPDATE" in a certain record with the duplicate values. I have tried with this query:
UPDATE Parametria.dbo.TABLA_INPUT_2 SET NUMERADOR = (SELECT COUNT(*) FROM FINREP.dbo.[CALIFICACION_SOFOM.CALIFICACION] HAVING COUNT(*)>1) WHERE ID_KQI = '003-RCDAT_D011-2';
SELECT * FROM Parametria.DBO.TABLA_INPUT_2
However, it brings me 338 values as output, they should be 337 because there is a record that is not duplicated
Could you tell me what I'm doing wrong in my query?
First of all, Thanks
This:
It retrieves only the rows that have duplicates, so you should only count the same ones like this:
Finally you nest everything in the update statement: