Remove duplicates groups
You can use the COUNT() OVER window function and PARTITION by your ID_GROUP field (in a series of CTEs) to filter on in the final query.
WITH CTE_Group AS
(
    SELECT
        DENSE_RANK() OVER(ORDER BY TicketId) AS ID_GROUP,
        CIId
    FROM TicketCIs
),
CTE_Group_Distinct AS
(
    SELECT
        ID_Group,
        CIId,
        COUNT(CIId) OVER (PARTITION BY ID_GROUP) AS DupeCount
    FROM CTE_Group 
)

SELECT ID_GROUP, CIId
FROM CTE_Group_Distinct
WHERE DupeCount = 1