Вы можете использовать оконную функцию как
SELECT *, DENSE_RANK() OVER(ORDER BY Market) [Group]
-- Or DENSE_RANK() OVER(ORDER BY COALESCE(Market, Cycle)) [Group] to get the exact results
FROM
(
VALUES
('A', NULL, NULL, NULL),
('A', '1', NULL, NULL),
('B', NULL, NULL, NULL),
('B', '3', 4, NULL),
('B', '3', 4, 5 ),
('A', '1', 2, NULL),
('A', '1', 2, 1 ),
(NULL, 'C', 6, 7 ),
(NULL, 'C', NULL, NULL),
('D', '8', NULL, NULL),
('D', '8', 9, NULL)
)T(Market, Cycle, Milestone, Sale)
Онлайн-демонстрация