选择重复的记录,其中一条记录必须包含相同的值


select duplicate records where one record must contain the exact value

我有一个表,有3列amount, frequency &标识符。所有这些记录都在同一个数据库的同一个表中。

amount     frequency       identifier
4.75        1                100
4.75        3                101
4.76        2                102
4.76        3                103
4.44        1                104
4.43        1                105
4.75        2                106
4.67        2                107
4.75        3                108
4.64        2                109
4.64        3                110
4.65        4                111

我是一个sql查询,应该拾取重复的记录为不同的频率,但其中一个频率必须等于1。所以我期望的输出是

amount  frequency   identifier
4.75        1       100
4.75        3       101
4.75        2       106
4.75        3       108

请注意,该查询与其他15个轻量级查询一起每2秒执行一次。我也可以在php中进行处理,但更喜欢数据库查询,只要它不是性能密集型的。我正在尝试不同的查询,但不能得到一致的结果。有人能帮帮我吗?

多谢

我认为这样的东西将是最快的方式得到你想要的:

select *
from t
where exists (select 1 from t t2 where t2.amount = t.amount and t2.frequency = 1)
如果在(amount, frequency)上有一个索引,这将运行得最快。