22,209
社区成员
发帖
与我相关
我的任务
分享
DECLARE @t_TB TABLE ([col1] NVARCHAR(5),[col2] int);
INSERT INTO @t_TB VALUES
('A','1'),
('A','2'),
('B','1'),
('B','1'),
('C','2'),
('C','3'),
('D','1'),
('D','3'),
('E','1'),
('E','1'),
('F','2'),
('F','2');
select col1 from @t_TB
where col2=1 and col1 in (
SELECT col1 FROM @t_TB
group by col1
having count(distinct col1+ltrim(col2)) =1
)
group by col1
/*
col1
-----
B
E
*/