I have this querry that gives me the total nr of rows that start with the same code
USE CCILCDatabase;
GO
DECLARE @mes int;
SET @mes = 1;
WHILE (select @mes) <= 12
BEGIN
SELECT LEFT(CONVERT(VARCHAR(10),[CPVCodeID]),2), COUNT(*)
FROM PublicContestCPV
where YEAR(DateCreated) = '2016' AND MONTH(DateCreated) = (select @mes) AND (PublicContestID in (SELECT ContestID FROM PublicContests where [UEPublicContestType] = ''))
GROUP BY LEFT(CONVERT(VARCHAR(10),[CPVCodeID]),2)
ORDER BY LEFT(CONVERT(VARCHAR(10),[CPVCodeID]),2)
SET @mes += 1;
END
PRINT @mes;
I needed, in addition to the count, to also show the% w / w of a column ( ContractValue ) that is in the PublicContests table. My SQL is not very trained, and this querry I need seems to me impossible.