如何获取mysql中所有值都相同的行

kuuvgm7e  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(423)

我有一张table:

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
nue99wik

nue99wik1#

试试这个:

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;

相关问题