SELECT count(*), lower(name), number FROM tbl GROUP BY lower(name), number HAVING count(*) > 1;
输入tb1
slno name number 1 aaa 111 2 Aaa 111 3 abb 221 4 Abb 121 5 cca 131 6 cca 141 7 abc 222 8 cse 222
该查询只能在数字和名称上找到相同的重复项,但无法在第3和第4行中找到重复项!!!
SELECT count(*), lower(name) FROM tbl GROUP BY lower(name) HAVING count(lower(name)) > 1
这个查询可以找到所有重复的名字!!!它完美地工作
SELECT count(*), number FROM tbl GROUP BY number HAVING count(number) > 1
这个查询可以找到所有重复的数字!!!它完美地工作
我想要一个查询,该查询可以查找名称和数字中的所有重复项,无论名称是否包含小写和大写
output name number count 2 111 aaa 2 --- abb 2 --- cca 2 222 ---
“在编号和名称上都获取重复” …“在不同的列上使用名称和编号” 在这里行可以被计数两次!
SELECT lower(name), NULL AS number, count(*) AS ct FROM tbl GROUP BY lower(name) HAVING count(*) > 1 UNION ALL SELECT NULL, number, count(*) AS ct FROM tbl GROUP BY number HAVING count(*) > 1;
- > sqlfiddle的
问题是查询分组依据
GROUP BY lower(name), number
由于第3行和第4行的内容 不同 number,因此此查询的内容不同。
number
如果要忽略此查询的其他数字,请尝试以下操作:
SELECT lower(name) , count(*) AS ct FROM tbl GROUP BY lower(name) HAVING count(*) > 1;