简体   繁体   English

如何获取那些在MySQL中所有值都相同的行

[英]How to fetch those rows where all values are same in mysql

I have a table: 我有一张桌子:

Unique Value        Remarks
URTA-144            ACC
URTA-144            ADD
URTA-144            ADT
URTA-145            ALL
URTA-145            ALL
URTA-145            ALL

I want to fetch those rows where for each distinct Unique Value I have same value in Remarks . 我想获取那些行,其中对于每个不同的Unique Value我在“ Remarks具有相同的值。

For Example: 例如:

Unique Value
URTA-145

Try this: 尝试这个:

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MySql:如何选择所有值都相同的行? - MySql: How to select rows where all values are the same? MySql计算日期行中包含(NULL)和'0000-00-00'值的所有元组 - MySql counting all those tupples where in Date Rows containing (NULL) and or '0000-00-00' values MySQL:选择所有行,但在列中具有指定值的行除外 - MySQL : Select all the rows except those having the specified values in columns 进行分组以避免在其中一个值发生更改的行之间返回具有相同列值集的行 - Grouping to avoid returning rows with the same set of column values between rows where one of those values changes 如何同时对值求和得到 mysql 中的所有行 - how to sum values at the same time getting all rows in mysql 如何对相同的行求和并找到在MySQL中高于平均水平的行? - How to sum same rows and find those that are above average in mySQL? 如何在mysql中按值获取所有行? - How to fetch all rows with group by value in mysql? MySQL:仅返回一个表中的行,其中另一个表的一列中的所有值都相同 - MySQL: Return only rows in one table where ALL values in one column of another table are the same 从表中全选所有具有相同外键的行中具有最高ID的行 - Select all from table where the rows has the highest id of all those with the same foreign keys 如何选择所有值,而不仅仅是where子句中的值 - How to select all values, not just those in where clause
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM