如何用 SQL 编写以下查询?我有一个表,其中 B 列错误地填充了重复值。找到这些重复项的最简单方法是与同一个表中的另一列 A 进行比较,这通常应该是一一对应,该表可能包含重复的列 B 值的多行
类似这样的事情
column A | column B
-------------------
00234211 | T 156
00011331 | T 157
00011331 | T 157
04600100 | T 157 <--- This is probably an erroneous value, show me every row for "T 157"
07740010 | T 159
我如何编写类似于这个可怕的伪代码的 SQL 查询
for all rows:
let A = columnA_value, B = columnB_value
for rows where columnA = A:
IF COUNT(columnB) > 1,
SHOW all rows WHERE columnA = A
最佳答案
嗯。我想你想要:
select t.*
from t
where exists (select 1 from t t2 where t2.b = t.b and t2.a <> t.a);
关于mysql - 对于sql中的每个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49520946/