Mysql 从重复值中选择行,其中字段从未更改

Mysql 从重复值中选择行,其中字段从未更改,mysql,sql,Mysql,Sql,身份证件 测试名称 结果 1. 性能测试1 通过 2. 性能测试1 失败 3. 性能测试1 失败 4. 烟雾9 失败 5. 烟雾9 失败 如果您只需要TestNames,您可以按TestName分组,并在HAVING子句中设置条件: select TestName from tablename group by TestName having sum(Result <> 'FAIL') = 0 请参阅。我尝试过使用SELECT TestName,COUNT(*),但我从来没有考虑过


身份证件
测试名称
结果
1.
性能测试1
通过
2.
性能测试1
失败
3.
性能测试1
失败
4.
烟雾9
失败
5.
烟雾9
失败

如果您只需要
TestName
s,您可以
按TestName
分组,并在
HAVING
子句中设置条件:

select TestName
from tablename
group by TestName
having sum(Result <> 'FAIL') = 0

请参阅。

我尝试过使用SELECT TestName,COUNT(*),但我从来没有考虑过失败和通过。工作非常出色,谢谢。结果是没有任何测试每次都失败了哈哈。为了以防万一,仔细检查了相反的内容,因此脚本确实可以用于将来的参考。
select t.* from tablename t
where not exists (select 1 from tablename where TestName = t.TestName and Result <> 'FAIL')