I got a situation where i have to show the first 9 rows with domain name of email and no of occurences of the email and the 10th row as the sum of the remaining domains and show it as others.
What i have done .
I have succesfully get the different domains and their occurrences using the below query
SELECT (SUBSTRING_INDEX(SUBSTR(email, INSTR(email, '@') + 1),'.',1)) as domain,
COUNT(*) as C
FROM newsletter_recipient
where LENGTH(email) > 0
GROUP BY (SUBSTRING_INDEX(SUBSTR(email, INSTR(email, '@') + 1),'.',1))
ORDER BY COUNT(*) DESC
Current Result
domain C
------------------------
gmail 12
dddd 2
mmmmm 2
dsf 2
aaaa 1
bbbb 1
ccc 1
yopmail 1
yahoo 1
dde 1
rfg 1
eedd 1
dfdg 1
sad 1
dfdf 1
sfd 1
web 1
Expected Result
domain C
------------------------
gmail 12
dddd 2
mmmmm 2
dsf 2
aaaa 1
bbbb 1
ccc 1
yopmail 1
yahoo 1
others 8
Hope Someone could help