我有下表,我必须从中获取非唯一行
+------+------+------+ | id | idA |infos | +----- +------+------+ | 0 | 201 | 1899 | | 1 | 205 | 1955 | | 2 | 207 | 1955 | | 3 | 201 | 1959 | +------+------+------+
我想获取column的所有行,至少在两行infos中具有相同的idA值。
infos
idA
上表查询的输出必须为
infos 1899 1959
我尝试了以下请求,但均未成功:
SELECT idA FROM XXX WHERE NOT EXISTS(SELECT * FROM XXX GROUP BY idA)
SELECT * FROM XXX a WHERE NOT EXISTS(SELECT * FROM XXX b WHERE a.RVT_ID=b.RVT_ID GROUP BY idA)
尝试这个:
SELECT T1.idA, T1.infos FROM XXX T1 JOIN ( SELECT idA FROM XXX GROUP BY idA HAVING COUNT(*) >= 2 ) T2 ON T1.idA = T2.idA
您发布的数据的结果:
idaA的相关信息 201 1899 201 1959