문제

I want to fetch duplicate email from table:

userid      email
-------------------------
1       abc@gmail.com
2       abcd@gmail.com
3       abc%40gmail.com
4       xyz@gmail.com
5       abcd%40gmail.com

So from above records i want result like

Email          Count
-------------------------
abc@gmail.com   2
abcd@gmail.com  2
xyz@gmail.com   1

Does anybody know how to manage that?

Thanks.

도움이 되었습니까?

해결책 2

You can't directly do that in MySQL because there is no function to urlencode or urldecode strings.

You will have to create a User Defined Function to handle that process. Once you have that function just go for a simple group by with a having clause.

Link to the required UDFs

If UDFs are not an option, the only workaround I can think of is manually replacing the chars (under your own risk):

SELECT REPLACE(email, "%40", "@") DuplicateEmail, COUNT(*) Amount
FROM t
GROUP BY DuplicateEmail
ORDER BY Amount desc

Fiddle here.

Output:

| DUPLICATEEMAIL | AMOUNT |
---------------------------
|  abc@gmail.com |      2 |
| abcd@gmail.com |      2 |
|  xyz@gmail.com |      1 |

다른 팁

If you want to output the data exactly like shown in your question, use this query:

SELECT email, COUNT(*) AS count
FROM table
GROUP BY email HAVING count > 0
ORDER BY count DESC;

Here is a simple solution:

SELECT email, COUNT(1) FROM table_name GROUP BY email HAVING COUNT(1) > 1
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top