我正在尝试检索ACL表中的重复项(我故意创建了一些)。
我写了一个查询来检索它们但不幸的是我的查询“不能完成这项工作”。我没有得到重复,而不是这个,我得到一个返回表ACL的完整视图(像select *一样),但项目已排序。内部有重复,但它们并不像我想的那样“孤立”。
使用此查询我只想检测重复项。 重复项适用于我:每列(索引除外)完全相同的信息,如:
1 TOTO BLABLA 123
2 TOTO BLABLA 123
然而这对我来说并不重复:
1 TOTO BLABLA 123
2 TOTO WHAOUH 123
我的MYSQL版本是5.0.2。
我已经用谷歌搜索了它,但不幸的是我无法以我想要的方式工作。
SELECT * FROM `acl` t1,
(SELECT `vara`, `varb`, `varc`, `vard`, `vare`, `varf`, `varg`, `varh`, `vari`, `varj`, `vark`, `varl`, `varm`, `varn`, `varo`, `varp`, `varq`, `varr`, `vars`, `vart`, `varu`, `varv`
FROM `acl`
GROUP BY `vara`, `varb`, `varc`, `vard`, `vare`, `varf`, `varg`, `varh`, `vari`, `varj`, `vark`, `varl`, `varm`, `varn`, `varo`, `varp`, `varq`, `varr`, `vars`, `vart`, `varu`, `varv`
) t2
WHERE
coalesce(t1.`vara`, '1') = coalesce(t2.`vara`, '1')
AND coalesce(t1.`varb`, '1') = coalesce(t2.`varb`, '1')
AND coalesce(t1.`varc`, '1') = coalesce(t2.`varc`, '1')
AND coalesce(t1.`vard`, '1') = coalesce(t2.`vard`, '1')
AND coalesce(t1.`vare`, '1') = coalesce(t2.`vare`, '1')
AND coalesce(t1.`varf`, '1') = coalesce(t2.`varf`, '1')
AND coalesce(t1.`varg`, '1') = coalesce(t2.`varg`, '1')
AND coalesce(t1.`varh`, '1') = coalesce(t2.`varh`, '1')
AND coalesce(t1.`vari`, '1') = coalesce(t2.`vari`, '1')
AND coalesce(t1.`varj`, '1') = coalesce(t2.`varj`, '1')
AND coalesce(t1.`vark`, '1') = coalesce(t2.`vark`, '1')
AND coalesce(t1.`varl`, '1') = coalesce(t2.`varl`, '1')
AND coalesce(t1.`varm`, '1') = coalesce(t2.`varm`, '1')
AND coalesce(t1.`varn`, '1') = coalesce(t2.`varn`, '1')
AND coalesce(t1.`varo`, '1') = coalesce(t2.`varo`, '1')
AND coalesce(t1.`varp`, '1') = coalesce(t2.`varp`, '1')
AND coalesce(t1.`varq`, '1') = coalesce(t2.`varq`, '1')
AND coalesce(t1.`varr`, '1') = coalesce(t2.`varr`, '1')
AND coalesce(t1.`vars`, '1') = coalesce(t2.`vars`, '1')
AND coalesce(t1.`vart`, '1') = coalesce(t2.`vart`, '1')
AND coalesce(t1.`varu`, '1') = coalesce(t2.`varu`, '1')
AND coalesce(t1.`varv`, '1') = coalesce(t2.`varv`, '1')
";
非常感谢您的回复!
答案 0 :(得分:0)
为什么不使用SELECT `vara`, `varb`, `varc`, `vard`, `vare`, `varf`, `varg`, `varh`, `vari`, `varj`, `vark`, `varl`, `varm`, `varn`, `varo`, `varp`, `varq`, `varr`, `vars`, `vart`, `varu`, `varv`
FROM `acl`
GROUP BY `vara`, `varb`, `varc`, `vard`, `vare`, `varf`, `varg`, `varh`, `vari`, `varj`, `vark`, `varl`, `varm`, `varn`, `varo`, `varp`, `varq`, `varr`, `vars`, `vart`, `varu`, `varv`
HAVING COUNT(*) > 1;
?
group_concat()
如果您想查看ID值,那么最简单的方法是添加SELECT group_concat(id) as ids,
`vara`, `varb`, `varc`, `vard`, `vare`, `varf`, `varg`, `varh`, `vari`, `varj`, `vark`, `varl`, `varm`, `varn`, `varo`, `varp`, `varq`, `varr`, `vars`, `vart`, `varu`, `varv`
FROM `acl`
GROUP BY `vara`, `varb`, `varc`, `vard`, `vare`, `varf`, `varg`, `varh`, `vari`, `varj`, `vark`, `varl`, `varm`, `varn`, `varo`, `varp`, `varq`, `varr`, `vars`, `vart`, `varu`, `varv`
HAVING COUNT(*) > 1;
:
{{1}}
答案 1 :(得分:0)
我解决了这个问题
SELECT count(*) count, `vara`, `varb`, `varc`, `vard`, `vare`, `varf`,
`varg`, `varh`, `vari`, `varj`, `vark`, `varl`, `varm`, `varn`,
`varo`, `varp`, `varq`, `varr`, `vars`, `vart`, `varu`, `varv` FROM `acl` GROUP BY `vara`, `varb`, `varc`, `vard`, `vare`, `varf`, `varg`, `varh`,
`vari`, `varj`, `vark`, `varl`, `varm`, `varn`, `varo`, `varp`,
`varq`, `varr`, `vars`, `vart`, `varu`, `varv` HAVING COUNT(*) > 1