我有一张桌子:
Unique Value Remarks
URTA-144 ACC
URTA-144 ADD
URTA-144 ADT
URTA-145 ALL
URTA-145 ALL
URTA-145 ALL
我想获取那些在Unique Value
中每个不同的Remarks
具有相同值的行。
例如:
Unique Value
URTA-145
答案 0 :(得分:2)
试试这个:
create table Tbl(UniqueValue char(8), Remarks char(3));
insert into Tbl values
('URTA-144', 'ACC'),
('URTA-144', 'ADD'),
('URTA-144', 'ADT'),
('URTA-145', 'ALL'),
('URTA-145', 'ALL'),
('URTA-145', 'ALL');
select UniqueValue from Tbl
group by UniqueValue
having count(distinct Remarks) = 1;