Q&A for students, teachers, and linguists wanting to discuss the finer points of the Chinese language
WITH posts_with_total_2_tags AS ( SELECT TOP 1000 PostId, COUNT(TagId) as tag_count FROM PostTags GROUP BY PostId HAVING COUNT(TagId) = 2 ), posts_with_total_2_tags_separated AS ( SELECT PostId, MIN(TagId) OVER (PARTITION BY PostId) as tag_min_id, MAX(TagId) OVER (PARTITION BY PostId) as tag_max_id FROM PostTags WHERE PostId IN (SELECT PostId FROM posts_with_total_2_tags) ), posts_with_total_2_tags_separated_names_added AS ( SELECT * FROM posts_with_total_2_tags_separated ), posts_with_total_2_tags_separated_grouped AS ( SELECT PostId, CAST(tag_min_id AS VARCHAR) + '-' + CAST(tag_max_id AS VARCHAR) as min_max_tag FROM posts_with_total_2_tags_separated_names_added GROUP BY PostId, CAST(tag_min_id AS VARCHAR) + '-' + CAST(tag_max_id AS VARCHAR) ) SELECT * FROM posts_with_total_2_tags_separated_names_added