已知条件 表t里有多行记录,同一个GroupID简称一个组,每一组的多行数字和其他其他一组里的数字是重复的就保留一次。
问题:如何用SQL判断不同的一组里每一行notext数字都是和其他一组里的notext数字是重复的,去重复后保留一次,请专家解答。
;with t(ID,GroupID,NoText) as(
select '1','1','1 2 3'
union all select '2','1','4 5 6'
union all select '3','1','7 8 9'
union all select '4','2','1 2 3'
union all select '5','2','4 5 6'
union all select '6','2','7 8 9'
union all select '7','3','2 3 4'
union all select '8','3','4 5 6'
union all select '9','3','7 8 9'
union all select '10','4','2 3 4'
union all select '11','4','4 5 6'
union all select '12','4','7 8 9'
union all select '13','5','1 2 3'
union all select '14','5','4 5 6'
union all select '15','5','6 7 8')
select ID,GroupID,NoText from t
WHERE ID in
(select min(id) from t group by notext)
order by GroupID
题主的代码执行的结果是错误的,实际上想要的结果
---------------------------
ID GroupID NoText
1 1 1 2 3
2 1 4 5 6
3 1 7 8 9
7 3 2 3 4
8 3 4 5 6
9 3 7 8 9
13 5 1 2 3
14 5 4 5 6
15 5 6 7 8